How to add section numbers (1.2, 3.4.1) automatically using CSS?

后端 未结 2 1623
感动是毒
感动是毒 2021-02-15 16:05

How to add section numbers (1.2, 3.4.1) automatically using CSS?

I currently have

h1, h2, h3, h4 {
  font-weight: normal;
}
h1 { font-size: 140%; }
h2 {          


        
2条回答
  •  我寻月下人不归
    2021-02-15 16:39

    Hey now you can used CSS counter-increment Property

    As like this Css

       body {counter-reset:section;}
        h1 {counter-reset:subsection;}
        h1:before
        {
        counter-increment:section;
        content:"Section " counter(section) ". ";
            font-weight:bold;
        }
        h2:before
        {
        counter-increment:subsection;
        content:counter(section) "." counter(subsection) " ";
        }
    

    HTML **

    Note: IE8 supports these properties only if a !DOCTYPE is specified.

    HTML tutorials

    HTML Tutorial

    XHTML Tutorial

    CSS Tutorial

    Scripting tutorials

    JavaScript

    VBScript

    Heading

    One

    Two

    **

    Live demo http://jsfiddle.net/PfcX2/1/

    More info click here https://developer.mozilla.org/en-US/docs/Web/CSS/counter-increment

提交回复
热议问题