CSS 属性选择器类以但不等于

标签 css css-selectors

我想将 css 应用于所有以“abcd-”开头的类,但我不想将该 css 应用于名称为“abcd-dontapply”的类。我可以这样做吗?

我尝试过的

 a[class |= "abcd"] :not([class = "abcd-dontapply"])
 {
     ---define CSS 
 }

但这不起作用,它没有将 CSS 应用于任何以“abcd-”开头的类。

最佳答案

如您的问题所述:

Don't add whitespace unnecessarily. The whitespace just before the :not is significant, i.e. it changes the meaning of the selector.


a[class^="abcd"]:not(.abcd-dontapply)
{
    /* define CSS here*/
}

您可以找到所有属性选择器规范 here .

关于CSS 属性选择器类以但不等于,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32637589/

相关文章:

html - :nth-child and :nth-of-type not working

css - 使用 CSS 选择器访问带有 selenium 的特定表行

javascript - 检查元素类名

css - 图标字体在 Opera Mobile 中不起作用

css - 编写 CSS 元素/分区的正确方法?

html - 为什么我的特定选择器不适用于 nth-of-type() 和 nth-child()?

html - 将鼠标悬停在父 div 上时,将子元素的第 n 个子元素作为目标?

css - 在 CSS 中使用毫米有多准确?

html - 如何使用 rowspan 将 <td> 与位置 :absolute? 合并

html - 社交图标悬停