簡體   English   中英

CSS“反增量”不遞增

[英]CSS “counter-increment” not incrementing

在學習完本教程之后 ,我試圖在<ol>列表項計數器的樣式。 但是,我的計數器沒有增加。

 .prog-ol ol { counter-reset:li; margin-left:0; padding-left:0; } .prog-ol li { position:relative; /* Create a positioning context */ margin:0 0 6px 2em; /* Give each list item a left margin to make room for the numbers */ padding:4px 8px; /* Add some spacing around the content */ list-style:none; /* Disable the normal item numbering */ } .prog-ol li:before { content:counter(li); /* Use the counter as content */ counter-increment:li; /* Increment the counter by 1 */ /* Position and style the number */ position:absolute; top:-2px; left:-2em; -moz-box-sizing:border-box; -webkit-box-sizing:border-box; box-sizing:border-box; width:2em; /* Some space between the number and the content in browsers that support generated content but not positioning it (Camino 2 is one example) */ margin-right:8px; padding:4px; border-top:2px solid #666; color:#fff; background:#666; font-weight:bold; font-family:"Helvetica Neue", Arial, sans-serif; text-align:center; } 
  <ol class="prog-ol"> <li>Foo</li> <li>Bar</li> <li>baz</li> </ol> 

似乎這兩行應該好好處理:

content:counter(li); /* Use the counter as content */
counter-increment:li; /* Increment the counter by 1 */

為什么我的計數器不增加?

您正在.prog-ol ol上定義計數器,它們是prog-ol類成員的元素的<ol>后代。

從選擇器中刪除ol

 .prog-ol { counter-reset:li; margin-left:0; padding-left:0; } .prog-ol li { position:relative; /* Create a positioning context */ margin:0 0 6px 2em; /* Give each list item a left margin to make room for the numbers */ padding:4px 8px; /* Add some spacing around the content */ list-style:none; /* Disable the normal item numbering */ } .prog-ol li:before { content:counter(li); /* Use the counter as content */ counter-increment:li; /* Increment the counter by 1 */ /* Position and style the number */ position:absolute; top:-2px; left:-2em; -moz-box-sizing:border-box; -webkit-box-sizing:border-box; box-sizing:border-box; width:2em; /* Some space between the number and the content in browsers that support generated content but not positioning it (Camino 2 is one example) */ margin-right:8px; padding:4px; border-top:2px solid #666; color:#fff; background:#666; font-weight:bold; font-family:"Helvetica Neue", Arial, sans-serif; text-align:center; } 
 <ol class="prog-ol"> <li>Foo</li> <li>Bar</li> <li>baz</li> </ol> 

(為此,您可能也應該從類名稱中刪除ol 。將類名稱綁定到特定元素沒有多大意義。可以根據需要將它們與類型選擇器結合使用)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM