2016-04-17 24 views
1

信我想信从我的下<ol>my question添加到<li> - 元素:一个风格的有序列表,其嵌套列表应该有一个数字使用CSS counter属性

body { counter-reset: item; } 
 

 
ol.numbered_style li:before 
 
{ 
 
    counter-increment:item; 
 
    margin-bottom:5px; 
 
    margin-right:10px; 
 
    content:counter(item); 
 
    background:blue; 
 
    border-radius:100%; 
 
    color:white; 
 
    width:1.2em; 
 
    text-align:center; 
 
    display:inline-block; 
 
} 
 
ol.numbered_style.start_3{ 
 
    counter-reset: item 2; 
 
} 
 

 
ol.none, ul.none,ol.numbered_style { list-style: none; }
<ol class="numbered_style"> 
 
\t <li>first</li> 
 
\t <li>second</li> 
 
\t <li>third Lorem Ipsum 
 
\t \t <ol class="numbered_style start_3"> 
 
\t \t \t <li>missing an a after the number</li> 
 
\t \t \t <li>missing a b after the number</li> 
 
\t \t \t <li>missing a c after the number</li> 
 
\t \t </ol> 
 
\t </li> 
 
</ol>
我已尝试,但这没有奏效。我还想要一个解决方案,其中添加第二个计数器可以使用以下字母数字模式生成下一个元素,如 list-style-type: lower-alpha;

回答

1

当然,您可以执行<ol>可以执行的任何操作。

ol.numbered_style.start_3{ 
    counter-reset: item2; 
} 

ol.numbered_style.start_3 li:before { 
    counter-increment:item2; 
    content:counter(item2, upper-latin); 
}/* List Style Type========^----------^*/ 

计数器列表样式类型

  • 小数--------------------------- ---- 1,2,3,...

  • 十进制前导零-------------- 01,02,03,... 09,10, 11,...

  • lower-alpha, lower-latin ----------- a,b,c,... z,aa,ab,...

  • upper-alpha, upper-latin ---- ------ A,B,C,... Z,AA,AB,...

  • lower-roman ------------------ ------ i,ii,iii,iv,v,vi,...

  • upper-roman --------------------- --- I,II,III,IV,V,VI ......

  • 星号-------------------------- --- *, **, ***, ...

REFERENCE

http://www.princexml.com/doc/5.1/counters/

SNIPPET

body { counter-reset: item; } 
 

 
ol.numbered_style li:before 
 
{ 
 
    counter-increment:item; 
 
    margin-bottom:5px; 
 
    margin-right:10px; 
 
    content:counter(item, upper-roman); 
 
    background:blue; 
 
    border-radius:100%; 
 
    color:white; 
 
    width:1.2em; 
 
    text-align:center; 
 
    display:inline-block; 
 
} 
 
ol.numbered_style.start_3{ 
 
    counter-reset: item2; 
 
} 
 

 
ol.numbered_style.start_3 li:before { 
 

 
    counter-increment:item2; 
 
    margin-bottom:5px; 
 
    margin-right:10px; 
 
    content:"3"counter(item2, upper-latin); 
 
    background:blue; 
 
    border-radius:100%; 
 
    color:white; 
 
    width:1.2em; 
 
    text-align:center; 
 
    display:inline-block; 
 
} 
 
    
 
ol.none, ul.none,ol.numbered_style { list-style: none; }
<ol class="numbered_style"> 
 
\t <li>first</li> 
 
\t <li>second</li> 
 
\t <li>third Lorem Ipsum 
 
\t \t <ol class="numbered_style start_3"> 
 
\t \t \t <li>missing an a after the number</li> 
 
\t \t \t <li>missing an b after the number</li> 
 
\t \t \t <li>missing an c after the number</li> 
 
\t \t </ol> 
 
\t </li> 
 
</ol>

+0

谢谢您的回答,但我想3A,3B,3C不但A,B,C – Grischa

+1

@Grischa查看更新后的演示内容': “3” 计数器(item2,上拉丁文);' – zer00ne

1

尝试了这一点:

ol.main { 
 
    counter-reset: item; 
 
} 
 
ol.main li { 
 
    counter-increment: item; 
 
} 
 
ol.numbered_style li:before { 
 
    margin-bottom: 5px; 
 
    margin-right: 10px; 
 
    content: counter(item); 
 
    background: blue; 
 
    border-radius: 100%; 
 
    color: white; 
 
    width: 1.2em; 
 
    text-align: center; 
 
    display: inline-block; 
 
} 
 
ol.numbered_style ol.numbered_style li { 
 
    counter-increment: subitem; 
 
} 
 
ol.numbered_style ol.numbered_style li:before { 
 
    content: counter(item) counter(subitem, lower-alpha); 
 
} 
 
ol.none, 
 
ul.none, 
 
ol.numbered_style { 
 
    list-style: none; 
 
}
<ol class="main numbered_style"> 
 
    <li>first</li> 
 
    <li>second</li> 
 
    <li>third Lorem Ipsum 
 
    <ol class="numbered_style"> 
 
     <li>missing an a after the number</li> 
 
     <li>missing a b after the number</li> 
 
     <li>missing a c after the number</li> 
 
    </ol> 
 
    </li> 
 
</ol> 
 

 
<hr> 
 

 
<ol class="main numbered_style"> 
 
    <li>first</li> 
 
    <li>second</li> 
 
    <li>third Lorem Ipsum 
 
    <ol class="numbered_style"> 
 
     <li>missing an a after the number</li> 
 
     <li>missing a b after the number</li> 
 
     <li>missing a c after the number</li> 
 
    </ol> 
 
    </li> 
 
</ol>

相关问题