26

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

<a class="" href="...">

Like a selector for empty class declarations?

2 Answers 2

35

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

jsFiddle

<a class="" href="...">asd</a>

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

<a href="...">asd</a>

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

These can then be combined together to handle both cases.

jsFiddle

<a href="...">asd</a>
<a class="" href="...">asd</a>

a[class=""],
a:not([class]) {
    color: red;
}
Sign up to request clarification or add additional context in comments.

Comments

31

You can use element-attribute selector here with an empty class value

div[class=""] {
    color: red;
}

Demo

Note: You can replace the div with required element

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.