.parent {
counter-reset: section;
}
.child:before {
counter-increment: section;
content: counters(section, ".") " ";
}
.red {
color: red;
margin-left: 19px;
}

<div class="parent ">
<!-- paragraph 1 -->
<p class="child">item</p>
<!-- paragraph 2 -->
<p class="child">item
<div class="parent red">
<p class="child">item</p>
<p class="child">item</p>
<p class="child">item
<p>
<p class="child">item</p>
</p>
</p>
</div>
</p>
<!-- paragraph 3 -->
<p class="child">item</p>
<!-- paragraph 4 -->
<p class="child">item</p>
</div>
&#13;
注意:如果我们将此计数器与<ol>
元素一起使用,
并且在内部增加和添加每个<li>
元素,该过程将自然地完成而不会混合。