2013-06-22 80 views
61

是否存在适用于非空属性的CSS选择器?如果属性不存在,则使用:not([Data-Attribute=''])匹配。用于非空属性的CSS属性选择器

我在寻找类似[Data-Attribute!='']的东西。

+0

这不会是类似''如果你谈论的jQuery选择,因为jQuery选择等同于'[数据属性=“”!]:不([Data-Attribute =''])'并且如果该属性没有被指定,则匹配。 – BoltClock

+0

[Select element where attribute is non-empty]可能重复(http://stackoverflow.com/questions/16429220/select-elements-where-attribute-is-non-empty) – user

回答

123

试试这个

<style> 
    [Data-Attribute]:not([Data-Attribute=""]) 
    { 
     background-color: Red; 
    } 
</style> 
+2

我见过更好(或不同)解决方案在这里:http://stackoverflow.com/questions/16429220/select-elements-where-attribute-is-non-empty – Sven

+4

@Sven该链接上唯一的解决方案,回答这个问题(选择一个特定的数据属性不是空的)与这个答案相同。 – rybo111

+0

是的,这里提供的解决方案的目标是他所需要的,上面的链接中需要反模式。 – will