It turns out that I once encountered some abnormal behavior in the UL list at work.
In addition, I saw the post http://bbs.blueidea.com/thread-2984871-1-1.html yesterday, so I tested various attributes of list-style and discovered an interesting phenomenon.
Let’s take a look at the explanation of list-style in the CSS manual first.
Definition and usage
The list-style shorthand attribute sets all list properties in one declaration.
illustrate
This property is a shorthand property that covers all other list style properties. Since it applies to all elements with a list-item display, it can only be used on li elements in normal HTML and XHTML, but in fact it can be applied to any element and is inherited by the list-item element.
The following properties can be set in order:
•list-style-type
•list-style-position
•list-style-image
It is not necessary to set one of the values. For example, "list-style:circle inside;" is also allowed. Properties that are not set use their default values.
Default value: disc outside none
In daily work, it is often necessary to perform css reset on ul and li to hide the list symbols.
The most commonly used way of writing is Ul,li,ol{list-style:none;} (some people also use ul,li,ol{list-style-type:none;})
Run code box
[Ctrl+A Select All Tips: You can modify part of the code first and then press Run]
There is no problem with this page in IE6, 7, 8, and FF.
But what we cannot ignore is that list-style: contains three attributes:
list-style-type
list-style-position
list-style-img
If you don't pay attention to these three attributes, list-style will sometimes cause trouble.
For example, when ul, after floating, needs display:inline to solve the double margin problem in IE6, something strange happens:
Run code box
[Ctrl+A Select All Tips: You can modify part of the code first and then press Run]
.ul01{float:left;display:inline;}
.ul01,.ul01 li{list-style:none;}
The above page is still normal in IE8 and ff, but in IE6 and 7, there is a distance between the inside of ul and li.
It can be seen that when we define list-style:none, although the list symbol does not appear, its position is still left in IE6 and 7.
See what attributes this UL has in FF
As can be seen from the picture, when list-style:none is defined in css, it has no effect on list-style-position. It is still the default setting of FF browser, and the value is outside.
In IE6 and 7, list-style-position: inside is likely to be the default
To confirm this, I changed list-style:none to list-style:none inside none and tested it again
Run code box
[Ctrl+A Select All Tips: You can modify part of the code first and then press Run]
After running it, you can find that in IE6 and 7, it behaves exactly the same as list-style:none.
So I speculate that in IE6 and 7, when UL has float:left and display:inline attributes and list-style:none is set, list-style-position also defaults to inside;
So the conclusion I came to is that under IE6 and 7, when UL does not have float:left;display:inline;:
Regardless of whether there is the attribute list-style:none, the list symbols are hidden and do not occupy space (5, 6 in the code below)
When UL has float:left;display:inline; attribute
list-style:none, the list symbol is hidden, but the position is still left (list-style-position:inside); (UL1, ul3 in the code below)
list-style:none is not set; the list character is hidden and does not occupy a position (list-style-position:outside) (code UL4)
UL02 performed relatively well in all browsers participating in the test.
This last piece of code compares the performance of list-style under various circumstances, especially the performance of 4, 5, and 6 under IE6 and 7.
Run code box
[Ctrl+A Select All Tips: You can modify part of the code first and then press Run]
By comparing the performance results of the above code, I think:
In Firefox, as long as list-style-type is none, no matter the value of list-stype-position is outside or inside, list-style can be well hidden. In IE6 and 7, only list-style:none is set. , is not enough to solve all problems, so I think it is better to use list-style:none outside none when css reset