This time to bring you a list of directories with serial numbers, to achieve the list of directories with serial number note what, here is the actual case, take a look.
When writing a documentation manual, we often need the sequence number in front of the list item to append the serial number of the upper layers to the front, as follows:
(Figure I)
But the default <ol> list, any level is a single ordinal start. Such as:
(Figure II)
To achieve the effect of the graph, one way is to directly insert the ordinal part as part of the list content, inserting the corresponding HTML, you can use JS BULK Insert sequence number.
Generated HTML results similar to this
<ol> <li>1. List items <ol> <li>1.1. List items <ol> <li>1.1.1 list Items </ li> <li>1.1.2 list items </li> <li>1.1.3 list items </li> </ol> </li> </ol> </li> </ol>
If you do not want to write the sequence number hard in the HTML code, and do not want to introduce JS, then only from the HTML properties and CSS two aspects to break through.
Unfortunately, the HTML element attribute does not provide a similar interface.
After netizens hint, know has a call CSS counter concept, I ignorant.
After querying the documentation, the CSS solution is also available.
The HTML code is as follows:
<ol> <li> list items <ol> <li> list items <ol> <li> list Items </li> <li> list Items </li> <li> list items </li> </ol> </li> </ol> </li> </ol>
The CSS code is as follows:
OL {padding:0 0 0 20px;margin:0;list-style:none;} Li:before {color: #f00; font-family:times New Roman;} Li{counter-increment:a 1;} Li:before{content:counter (a) ". ";} Li Li{counter-increment:b 1;} Li Li:before{content:counter (a) "." Counter (b) ". ";} Li Li li{counter-increment:c 1;} Li Li Li:before{content:counter (a) "." Counter (b) "." Counter (c) ". ";}
The effect is the beginning of this chapter of Figure I.
But this CSS is really ugly, there are a few levels of the directory, you have to write a few layers of CSS, obviously should not be such a son.
Continue to read the relevant documents, clear Counter-reset, counter (), counters (), found that the problem is unexpectedly simple.
The CSS code is as follows:
OL {padding:0 0 0 20px;margin:0;list-style:none;counter-reset:a;} Li:before {counter-increment:a;content:counters (A, ".") ". ";}
In this way, no matter how many layers of nested list, can correctly display the cascading sequence number, the effect as shown in the beginning of Figure I.
It should be noted that: before, counter-increment and other related CSS features do not support the old ie6/ie7, but IE8 and above are supported very well.
Believe that you have read the case of this article you have mastered the method, more exciting please pay attention to the PHP Chinese network other related articles!
Recommended reading:
What is the difference between href and src, link, and @import?
How the absolute positioning of CSS is compatible with all resolutions
Properties of CSS3 Transition, animation, transform