2

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

<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>
4

2 回答 2

7

如果要输出编号列表,最好的方法是使用<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>

于 2015-05-11T08:02:31.937 回答
2

CSS

.esum {
  display: list-item;
  margin-left: 1.5em;
  list-style-type: decimal;
}

将上述CSS添加到您的 CSS 文件中

演示

于 2015-05-11T08:06:21.657 回答