Implementation of counters in css-notes and css counters

Source: Internet
Author: User

Implementation of counters in css-notes and css counters


Reference http://mp.weixin.qq.com/s? _ Biz = MzU3MDA0NTMzMA ==& mid = 2247485533 & amp; idx = 1 & amp; sn = e88dc5fffa60aeec13b341c1b90954dd & source = 41 # wechat_redirect

Knowledge Used
Pseudo class
Counter-reset attribute, set the incremental start
Counter-increment attribute, set the Incremental Value
Content attribute calculation Increment
Counter Function

The code format is as follows. Note the following:

<! -- Count every ul from 1 and display numbers -->
<! -- Each li starts counting from 1 in ul -->
<Ul class = "box"> Title 1
<Li> content 1 </li>
<Li> content 2 </li>
<Li> content 3 </li>
<Li> content 4 </li>
</Ul>
<Ul class = "box"> Title 2
<Li> content 1 </li>
<Li> content 2 </li>
<Li> content 3 </li>
<Li> content 4 </li>
</Ul>
<Ul class = "box"> Title 3
<Li> content 1 </li>
<Li> content 2 </li>
<Li> content 3 </li>
<Li> content 4 </li>
</Ul>

<Style>

Body {
/* The name can be customized, but it must be defined on the parent container of the container you want to count */
Counter-reset: startVal;
}

Ul {
/* Name */
Counter-reset: contentCounter;
}

/* Use the pseudo class in css */
Ul: before {
/* Defines the increment. The first parameter is the start value, and the second parameter is the increment value, either positive or negative */
Counter-increment: startVal 3;
/* Here is the counting function. The first parameter is the start value, and the second parameter is the display style. The specific parameters are not listed. The smart prompt is displayed */
Content: 'The title is displayed here -- 'counter (startVal );
}

Li: before {
Counter-increment: contentCounter;
Content: 'content list -- 'counter (contentCounter );
}
</Style>

 

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.