简体   繁体   English

一起使用CSS伪和属性选择器

[英]Using CSS pseudo and attribute selectors together

Because of a bug in webkit browsers, you can't use attribute and :before/:after classes by default. 由于Webkit浏览器中的错误,默认情况下,您不能使用attribute和:before /:after类。

The fix doesn't seem to have any effect when using nth-last-of-type selector. 使用nth-last-of-type选择器时,该修补程序似乎没有任何作用。

Here's what I'm doing: 这是我在做什么:

    .left[class^='col']:nth-last-of-type{
        margin-right: 0 !important;
    }

Just wanted to check and see if I'm not overlooking something simple. 只是想检查一下,看看我是否没有忽略简单的事情。

Your :nth-last-of-type syntax is a bit off — it's either :last-of-type or functional :nth-last-of-type() with a formula an+b as an argument. 您的:nth-last-of-type语法有点不对劲-它是:last-of-type或功能性:nth-last-of-type() ,其中公式an+b作为参数。

The pseudo-classes pertaining to "type" refer to the element type, represented by its tag name. 与“类型”有关的伪类是指元素类型,由其标签名称表示。 It does not mean "the last element matching the rest of this selector". 这并不意味着“与该选择器的其余部分匹配的最后一个元素”。

If, for example, the last element matching .left[class^='col'] is not the last span element, then :last-of-type will not match. 例如,如果与.left[class^='col']匹配的最后一个元素不是最后一个span元素,则:last-of-type将不匹配。 You'll have to modify your HTML to either segregate those span elements from others, or add a class to the last such element, before you can target it with a selector. 您必须修改HTML才能将这些span元素与其他元素分隔开,或者在最后一个此类元素中添加一个类,然后才能使用选择器将其定位。

WebKit does not have any issues with pseudo-classes and attribute selectors that I'm aware of (or if it did, those issues have long been fixed). WebKit对我所知道的伪类和属性选择器没有任何问题(或者,如果确实存在,则这些问题早已得到解决)。 It does have issues with pseudo- elements , which I address here , where the fiddle link originates. 它确实存在伪元素的问题,在这里我要解决的是伪造链接的起源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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