css - 如何将 CSS 规则应用于其中包含特定关键字的类?

标签 css css-selectors

也就是说,看下面:

<div class="helloeverybody">
</div>
<div class="heyeveryperson">
</div>

我想将 css 规则应用于每个类,其中包含单词“every”。 这个有正式名称吗?

最佳答案

您可以通过在属性后附加星号来使用“包含” 属性选择器 - 例如

div[class*=every] {
    color: orange;
}

http://jsfiddle.net/FWP8j/1/

来自 Selectors Level 3 的定义:

Represents an element with the att attribute whose value contains at least one instance of the substring "val". If "val" is the empty string then the selector does not represent anything.

关于css - 如何将 CSS 规则应用于其中包含特定关键字的类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18163533/

相关文章:

javascript - :focus pseudo selector style not being removed when a new tab is opened , 即使触发了模糊事件

jquery - css 选择器不是最后一个子元素不工作(需要纯 css 解决方案)

html - 我可以仅在与 div 关联的伪元素内使用 CSS 属性水平对齐两个 div 吗?

javascript - 使用文本输入调整 div 填充

html - 通过 CSS 访问 html 内容?

html - 在导航悬停上添加底部边框而不更改下方所有内容的位置

html - CSS第一个 child 不工作

javascript - Bootstrap tooltip交互和自动隐藏

javascript - css dom 操作 Angular 组件到 html-css

jquery - 禁用网页上的选择,但不能在表单上禁用选择,否则人们无法通过鼠标选择输入字段