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

时间:2022-11-25 20:06:08

I have div tags with span tag. How to add numbered list for the div tag using classname in CSS or JavaScript

我有带有span标签的div标签。如何使用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 个解决方案

#1


6  

If you want to output a numbered list, the best approach is to make use of <ol> tags but if you can't modify your HTML and still need to output as a numbered list, you can make use of CSS counters to achieve the numbered list behavior.

如果要输出编号列表,最好的方法是使用

    标签,但如果不能修改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>

#2


2  

CSS

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

Add the above CSS to you CSS File

将上面的CSS添加到CSS文件中

DEMO

#1


6  

If you want to output a numbered list, the best approach is to make use of <ol> tags but if you can't modify your HTML and still need to output as a numbered list, you can make use of CSS counters to achieve the numbered list behavior.

如果要输出编号列表,最好的方法是使用

    标签,但如果不能修改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>

#2


2  

CSS

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

Add the above CSS to you CSS File

将上面的CSS添加到CSS文件中

DEMO