CSS Shorthand来标识多个类 [英] CSS Shorthand to identify multiple classes
问题描述
我阅读了有关使用CSS选择器使用正则表达式的本教程和我试图外推:有一个CSS的速记以下?我想选择所有的div与类foo有一个额外的类a,b,c或d。
I read this tutorial on using regular expressions with CSS selectors and am trying to extrapolate: Is there a CSS shorthand to do the following? I want to select all div's with class of "foo" that have either an additional class of "a", "b", "c", or "d".
.foo.a,
.foo.b,
.foo.c,
.foo.d {
/* stuff */
}
例如:
.foo [class〜='a','b','c','d'] {}
?
推荐答案
这是不可能的,目前(使用Selectors 3推荐)。
It's not possible, currently (with the Selectors 3 recommendation). There isn't a full-fledged regex grammar for CSS, nor is there a way to crunch down parts of multiple selector lists.
选择器4提出了一个新的 :matches()
pseudo-class基于Mozilla的原始:any()
实现(请参阅此回答有一点历史):
Selectors 4 proposes a new :matches()
pseudo-class based on Mozilla's original :any()
implementation (see this answer for a bit of history):
.foo:matches(.a, .b, .c, .d)
不要期望浏览器支持这个。我可能甚至忘记更新这个答案,当时间到了,我们会看到。
Of course, don't expect browser support for this yet. I might even forget to update this answer when that time comes but... we'll see.
这篇关于CSS Shorthand来标识多个类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!