简体   繁体   中英

Where should the list-style CSS property go?

Should the list styling properties go on the ul element or the li elements?

I have never seen lists with different little icons to the left of them (within the same ul), but I have seen the property used on both elements before in my travels.

Which one is correct?

It should go on the ul/ol, cf. http://www.w3.org/TR/CSS2/generate.html#list-style

Edit : Near the bottom ( http://www.w3.org/TR/CSS2/generate.html#propdef-list-style ) you will find a discussion of the issue. It boils down to:

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.

According to this ,

The list-style property is a shorthand property for setting all the properties for a list in one declaration.

ul
{
    list-style: disc outside
} 

I suggest to put it on the ul / ol . If you'd put it on the li , it would apply to both ordered and unordered lists, which is probably not what you want (the numbering would disappear).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM