css - 是:not possible on a wildcard attribute selector

标签 css css-selectors

是否可以在通配符属性选择器上使用 :not 选择器?

例子:

<div class="circle circle-red"></div>
<div class="circle circle-blue"></div>
<div class="circle circle-yellow"></div>
<div class="circle"></div>

我只想处理类为“circle”的 div,而不是类为“circle-red”、“circle-blue”、“circle-yellow”的 div

最佳答案

为此,您可以使用否定选择器 (:not) 以及属性contains 选择器。

选择器 div.circle:not([class*="circle-"]) 将只选择包含 circlediv > 类,但不包含格式为 circle- 的任何其他类。

div.circle:not([class*="circle-"]) {
  color: green;
}
<div class="circle circle-red">Red</div>
<div class="circle circle-blue">Blue</div>
<div class="circle circle-yellow">Yellow</div>
<div class="circle">None</div>
<div class="circle-orange">Orange</div>

关于css - 是:not possible on a wildcard attribute selector,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37544252/

相关文章:

html - (Bootstrap 3) 如何让小屏幕上的导航栏与大屏幕上的导航栏显示相同

docker 构建后 css 文件完整性检查失败

CSS 选择器,但不是在存在另一个类时

CSS - 优先css规则

css - 覆盖 TD :first-child with TR:hover?

jquery - 单击选项卡时的 Div 动画

html - 边界半径间隙

html - 水平居中页脚 div

html - CSS :first-child and :first-of-type (example)

html - 在 CSS3 中使用 nth-child() 选择 double