我有div标记的span标记。如何使用CSS或JavaScript中的类名为div标签添加编号列表

<div id="editsum">
    <div class="esum"><span id="1430568488933" class="tbold">nde</span></div>
    <div class="esum"><span id="1430568576033" class="tbold">ca</span></div>
    <div class="esum"><span id="1430568582173" class="tdel">tim</span></div>
    <div class="esum"><span id="1430568582173" class="tins">Ó</span></div>
    <div class="esum"><span id="1430914284123" class="tdel">non</span></div>
    <div class="esum"><span id="1430914309275" class="tdel">cu</span></div>
</div>

最佳答案

如果要输出编号列表,最好的方法是使用<ol>标记,但是如果您无法修改HTML并仍然需要输出为编号列表,则可以使用CSS计数器来获得编号列表行为。

body {
  counter-reset: esum;
}
.esum {
  position: relative;
  counter-increment: esum;
  padding: 10px;
}
.esum:before {
  content: counter(esum)".";
}
<div class="esum"><span id="1430568488933" class="tbold">nde</span>
</div>
<div class="esum"><span id="1430568576033" class="tbold">ca</span>
</div>
<div class="esum"><span id="1430568582173" class="tdel">tim</span>
</div>
<div class="esum"><span id="1430568582173" class="tins">Ó</span>
</div>
<div class="esum"><span id="1430914284123" class="tdel">non</span>
</div>
<div class="esum"><span id="1430914309275" class="tdel">cu</span>
</div>

07-24 19:12