当前位置:  开发笔记 > 编程语言 > 正文

如何自定义有序列表中的数字?

如何解决《如何自定义有序列表中的数字?》经验,为你挑选了6个好方法。

如何在有序列表中左对齐数字?

1.  an item
// skip some items for brevity 
9.  another item
10. notice the 1 is under the 9, and the item contents also line up

更改有序列表中的数字后面的字符?

1) an item

还有一个CSS解决方案,可以从数字更改为字母/罗马列表,而不是使用ol元素上的type属性.

我最感兴趣的是适用于Firefox 3的答案.



1> grom..:

这是我在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;
}
  1. One
  2. Two
  3. Three
  4. Four
  5. Five
  6. Six
  7. Seven
  8. Eight
  9. Nine
    Items
  10. Ten
    Items


2> Marcus Downi..:

样式列表的CSS在这里,但基本上是:

li {
    list-style-type: decimal;
    list-style-position: inside;
}

但是,你可能只能通过钻研的东西,如布局的内部结构来实现后是具体布局这个(请注意,我还没有真正尝试过):

ol { counter-reset: item }
li { display: block }
li:before { content: counter(item) ") "; counter-increment: item }



3> z0r..:

您还可以在HTML中指定自己的数字 - 例如,如果数字由数据库提供:

ol {
  list-style: none;
}

ol>li:before {
  content: attr(seq) ". ";
}

seq使用类似于其他答案中给出的方法使该属性可见.但content: counter(foo)我们不使用,而是使用content: attr(seq):

  1. Item one
  2. Item twenty
  3. Item three hundred

CodePen中的演示具有更多样式


如果只使用`
  • `上的`value`属性,可以简化这个.例如`
  • `.那你就不需要任何伪元素了.[演示](http://codepen.io/anon/pen/EPbZJM)

    4> Steve Perks..:

    从其他答案中偷了很多这个,但这对我来说在FF3中有效.它有upper-roman均匀的凹痕,一个紧密的支架.

    
    
    
     new document 
    
    
    
    
    
    1. One
    2. Two
    3. Three
    4. Four
    5. Five
    6. Six
    7. Seven
    8. Eight
    9. Nine
    10. Ten



    5> Marcus Downi..:

    我建议使用:before属性,看看你能用它实现的目标.这将意味着你的代码确实是有限的,以漂亮的新的浏览器,并排除市场仍然使用旧的垃圾浏览器(烦人大)部分,

    类似下面的内容,强制固定在项目上.是的,我知道这是那么优雅有自己选择的宽度,但使用CSS布局就像是卧底警察的工作:但是好你的动机,它总是会混乱.

    li:before {
      content: counter(item) ") ";
      counter-increment: item;
      display: marker;
      width: 2em;
    }
    

    但是你将不得不尝试找到确切的解决方案.



    6> Peter Hilton..:

    如果通过将list-style-type设置为:向数字添加前导零,则数字排列更好:

    ol { list-style-type: decimal-leading-zero; }
    

  • 推荐阅读
    赛亚兔备_393
    这个屌丝很懒,什么也没留下!
    DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
    Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有