Select an element with empty class attribute (class=“”) using CSS?

后端 未结 2 589
我在风中等你
我在风中等你 2020-12-03 21:22

Is there a CSS way to select an element that looks like that by class?


Like a selector for empty class de

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-03 21:27

    Provided the class attribute is present as you say you can use the attribute selector like this:

    jsFiddle

    asd
    
    a[class=""] {
        color: red;
    }
    

    If you want this to work when there is no class attribute present on the element you can use :not([class]).

    jsFiddle

    asd
    
    a:not([class]) {
        color: red;
    }
    

    These can then be combined together to handle both cases.

    jsFiddle

    asd
    asd
    
    a[class=""],
    a:not([class]) {
        color: red;
    }
    

提交回复
热议问题