Deep understanding of CSS counters and deep understanding of css

Source: Internet
Author: User

Deep understanding of CSS counters and deep understanding of css
Directory [1] Create counter [2] use counter [3] Before DEMO

We are no longer familiar with counters. The list item mark in the ordered list is the counter.

 

Create a counter

There are two basic aspects for creating a counter: one is to reset the starting point of the counter, and the other is to increase it by a certain amount.

Counter-reset
Counter-reset: none; (default) counter-reset: <identifier> <integer> // <identifier> is the counter identifier, is a name set by the creator. // <integer> is a reset number.
Counter-reset: c1 4; // indicates resetting the c1 counter to 4counter-reset: c1 4 c2 0 c3-5; // indicates resetting c1 to 4, reset c2 to 0 and c3 to-5couter-reset: c1; // reset c1 to 0

[Note] If <integer> is not set, the default value is 0.

 

Counter-increment
Counter-increment: none; (default) counter-increment: <identifier> <integer> // <identifier> is the counter identifier, is the name of the creator. // <integer> is an incremental number.
Counter-increment: c1 4; // sets the increase of the c1 counter to 4 counter-reset: c1 4 c2 0 c3-5; // sets the increment of c1 to 4, set c2 to 0 and c3 to-5 couter-increment: c1; // set c1 to 1

[Note] If <integer> is not set, the default increment is 1.

 

Use counters

The content attribute and counter () function must be used in combination to use counters.

Counter () function

The counter () function accepts two parameters, which are separated by commas (,). The first parameter is the counter identifier, and the second parameter sets the counter style (which can be omitted ), the value is the same as the value of list-style-type in the list. Similarly, multiple counter () functions can be used.

Content: counter (c1, upper-roman); // counter c1 that uses uppercase letters and Rome

[The following is a detailed demonstration of the counter style]

<Demo Box> click the following attribute values for demonstration.

 

DEMO simple counter DEMO

<Demo Box> click the following attribute values for demonstration.

View code

 

Hierarchical directory demo

<Demo Box> click the following attribute values for demonstration.

<Div id = "oShow"> 
body,h2,h3,p{    margin: 0;}    #oShow{    counter-reset: c2;}#oShow h2{    counter-reset: c3 cp;    counter-increment: c2;}#oShow h3{    counter-increment: c3;        counter-reset: cp;    text-indent: 2em;}#oShow p{    counter-increment: cp;     text-indent: 4em;   }#oShow h2:before{    content: counter(c2);}#oShow h3:before{    content: counter(c2) '.' counter(c3);}#oShow p:before{    content: counter(c2) '.'  counter(c3)  '.' counter(cp);    }

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.