CSS属性选择器类以(但不等于)开头 [英] CSS attribute selector class starts with but not equals to

查看:716
本文介绍了CSS属性选择器类以(但不等于)开头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

我尝试过的

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

但是这不起作用,它没有将CSS应用于以'abcd-'开头的任何类.

解决方案

如您的问题所述:

不要不必要地添加空格.空格之前 :不重要,即会更改选择器的含义.


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

您可以在此处找到所有属性选择器规范./p>

I want to apply css to all class that starts with for example 'abcd-' but I don't want to apply that css to class with name for example 'abcd-dontapply'. Can I do this?

What I tried

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

But this is not working, it is not applying CSS to any class that starts with 'abcd-'.

解决方案

As mentioned in your question:

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*/
}

You can find all attribute selectors specifications here.

这篇关于CSS属性选择器类以(但不等于)开头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆