如何自定义有序列表中的数字?如何在有序列表中左对齐数字?1. an item// skip some items for brevity 9. another item10. notice the 1 is under the 9, and the item contents also line up更改有序列表中的数字后面的字符?1) an item还有一个CSS解决方案,可以从数字更改为字母/罗马列表,而不是使用ol元素上的type属性。我最感兴趣的是适用于Firefox 3的答案。
3 回答

呼如林
TA贡献1798条经验 获得超3个赞
这是我在Firefox 3,Opera和Google Chrome中使用的解决方案。该列表仍显示在IE7中(但没有关闭括号和左对齐数字):
ol { counter-reset: item; margin-left: 0; padding-left: 0;}li { display: block; margin-bottom: .5em; margin-left: 2em;}li::before { display: inline-block; content: counter(item) ") "; counter-increment: item; width: 2em; margin-left: -2em;}
<ol> <li>One</li> <li>Two</li> <li>Three</li> <li>Four</li> <li>Five</li> <li>Six</li> <li>Seven</li> <li>Eight</li> <li>Nine<br>Items</li> <li>Ten<br>Items</li></ol>
编辑:由strager包含多行修复
还有一个CSS解决方案,可以从数字更改为字母/罗马列表,而不是使用ol元素上的type属性。
请参阅list-style-type CSS属性。或者在使用计数器时,第二个参数接受list-style-type值。例如,以下将使用上罗马:
li::before { content: counter(item, upper-roman) ") "; counter-increment: item;/* ... */

心有法竹
TA贡献1866条经验 获得超5个赞
您还可以在HTML中指定自己的数字 - 例如,如果数字由数据库提供:
<ol> <li seq="1">Item one</li> <li seq="20">Item twenty</li> <li seq="300">Item three hundred</li></ol>
seq
使用类似于其他答案中给出的方法使该属性可见。但content: counter(foo)
我们不使用,而是使用content: attr(seq)
:
ol { list-style: none;}ol > li:before { content: attr(seq) ". ";}
- 3 回答
- 0 关注
- 688 浏览
相关问题推荐
添加回答
举报
0/150
提交
取消