CSS Shorthand to identify multiple classes(用于识别多个类的 CSS 速记)
问题描述
我阅读了关于在 CSS 选择器中使用正则表达式的本教程并试图推断:是否有 CSS 速记来执行以下操作?我想选择具有a"、b"、c"或d"附加类的foo"类的所有 div.
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 建议).CSS 没有成熟的正则表达式语法,也没有办法分解多个选择器列表的一部分.
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.
Selectors 4 提出了一个新的 :matches()
基于 Mozilla 原始 :any()
实现的伪类(参见 this answer 了解一些历史):
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 速记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:用于识别多个类的 CSS 速记


基础教程推荐
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01