Most sites show the syntax as applying list-style
to the <li>
but I've seen some tutorial sites (like this one) that apply list-style
to t开发者_如何转开发he <ul>
or <ol>
.
Which is the 'correct' way?
According to the W3C CSS2 reference, which can be found here,
Another solution would be to specify 'list-style' information only on the list type elements:
ol.alpha { list-style-type: lower-alpha } ul { list-style-type: disc }
Inheritance will transfer the 'list-style' values from OL and UL elements to LI elements. This is the recommended way to specify list style information.
So you can do it at the overall list level if all of your elements are going to be the same, but you can instead do it at the list entry level if for example some entries would have different glyphs (like a square instead of a disc) to convey some meaning. You can also do both, with the list level style serving as a default to be overridden (but be careful about selector precedence!).
As not having a list style is generally more common that having a list style, I personally apply it to both in a global reset at the top of my stylesheet.
The spec recommends that you that you set it on <ul>
and <ol>
tags, and not on <li>
.
See http://www.w3.org/TR/REC-CSS1/#list-style
精彩评论