CSS中使用counter()在列表中自動添加序號

來源:互聯網
上載者:User

   在CSS 2.1在就已經支援的功能是counter(),使用它,你能方便的在頁面標題,區塊和其它各種連續出現的頁面內容上添加序號。有了它,你就不必限制於只能使用

    來實現這個效果,你可以更靈活的在頁面上使用自訂數字序列。

     

      關鍵就是它真的很簡單:在:before偽類裡的content屬性加入counter():

      body {

      counter-reset: heading;

      }

      h4:before {

      counter-increment: heading;

      content: "Heading #" counter(heading) ".";

      }

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.