多个CSS伪类 [英] Multiple CSS Pseudo Classes
问题描述
将多个伪类应用于选择器的正确CSS语法是什么。我想在列表中除了最后一个项目之外的每个项目之后插入,。我使用以下css:
ul.phone_numbers li:after {
content:,;
}
ul.phone_numbers li:last-child:after {
content:;
}
这在FF3,Chrome和Safari 3上可以正常工作。IE7不工作因为它不支持:after(如预期)。在IE 8中,在每个li包括最后一个之后使用逗号。这是IE8的问题还是我的语法不正确?它的确定,如果它不能在IE8工作,但我想知道正确的语法是什么。
:last-child
是一个伪类,:之后
(或 :: after $
伪类被允许在任何地方选择而伪元素只可以选择的最后一个简单选择之后追加。
块引用>
这意味着你的语法根据CSS2是正确的.1和 CSS3以及,也就是说IE8仍然很烂;)
What is the proper CSS syntax for applying multiple pseudo classes to a selector. I'd like to insert "," after each item in a list except the last one. I am using the following css:
ul.phone_numbers li:after { content: ","; } ul.phone_numbers li:last-child:after { content: ""; }
This works fine on FF3, Chrome and Safari 3. IE7 doesn't work because it doesn't support :after (as expected). In IE 8 this renders with a comma after each li including the last one. Is this a problem with IE8 or is my syntax incorrect? It's ok if it doesn't work in IE8 but I would like to know what the proper syntax is.
解决方案
:last-child
is a pseudo-class, whereas:after
(or::after
in CSS3) is a pseudo-element.To quote the standard:
Pseudo-classes are allowed anywhere in selectors while pseudo-elements may only be appended after the last simple selector of the selector.
This means your syntax is correct according to CSS2.1 and CSS3 as well, i.e. IE8 still sucks ;)
这篇关于多个CSS伪类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!