2011-10-17 32 views

回答

8

是,在现代浏览器至少:

li li:before { 
    counter-increment: item; 
    content: counter(item) ". "; 
} 

(该li li是所以只有第一层之后做到这一点)

你可能需要counter-reset为好。

+0

这工作?太好了! – knittl

+0

谢谢,阿里尔。为了使它工作,我添加了更多。 – Rocky

+0

但是,我们需要为此处理每个级别。有点烦人。 HTML5是否处理得更好? – Rocky

0
body 
{ 
    counter-reset:section; 
} 

h1 
{ 
    counter-reset:subsection; 
} 

h1:before 
{ 
    counter-increment:section; 
    content:"Section " counter(section) ". "; 
} 

h2:before 
{ 
    counter-increment:subsection; 
    content:counter(section) "." counter(subsection) " "; 
} 
body 
{ 
    counter-reset:section; 
} 

这是计数器增量和计数器复位的示例。

13

该解决方案适用于我:

/* hide original list counter */ 
ol li {display:block;} 
/* OR */ 
ol {list-style:none;} 

ol > li:first-child {counter-reset: item;} /* reset counter */ 
ol > li {counter-increment: item;} /* increment counter */ 
ol > li:before {content:counters(item, ".") ". "; font-weight:bold;} /* print counter */ 
+0

我对代码进行了一些修改,使其符合我的口味。它位于另一个类似的问题:http://stackoverflow.com/questions/4098195/can-ordered-list-produce-result-that-looks-like-1-1-1-2-1-3-instead-的-刚刚25298818分之1#25298818 – chelder

相关问题