如何在div标签中添加编号列表样式

时间:2015-05-11 07:58:38

标签: javascript css css-counter

我有div个标记span。如何使用CSS或JavaScript中的classname为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>

2 个答案:

答案 0 :(得分:6)

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

答案 1 :(得分:2)

<强> CSS

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

将以上 CSS 添加到CSS文件

DEMO