2011-10-17 18 views

Trả lời

8

Vâng, ít nhất là trong một trình duyệt hiện đại:

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

(. Các li li là vì vậy nó chỉ thực hiện điều này sau khi mức độ đầu tiên)

Bạn sẽ có lẽ cần counter-reset là tốt.

+0

này hoạt động? Tốt đẹp! – knittl

+0

Cảm ơn, Ariel. Tôi thêm một số chi tiết cho điều này để làm cho nó hoạt động. – Rocky

+0

Nhưng, chúng ta cần phải xử lý mọi cấp độ cho việc này. Một chút khó chịu. HTML5 có xử lý tốt hơn không? – 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; 
} 

Đây là mẫu đếm ngược và đặt lại bộ đếm.

13

Giải pháp này làm việc cho tôi:

/* 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

Tôi đã sửa đổi một chút mã của bạn phù hợp với khẩu vị của tôi. Nó nằm trong một câu hỏi tương tự khác: http://stackoverflow.com/questions/4098195/can-ordered-list-produce-result-that-looks-like-1-1-1-2-1-3-instead- của-just-1/25298818 # 25298818 – chelder

Các vấn đề liên quan