24

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?

Mr. Alien
  • 153,751
  • 34
  • 298
  • 278
user1856596
  • 7,027
  • 10
  • 41
  • 63

2 Answers2

34

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;
}
BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
Daniel Imms
  • 47,944
  • 19
  • 150
  • 166
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

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
Mr. Alien
  • 153,751
  • 34
  • 298
  • 278
  • @e1che Good :) and glad it was useful and user1856596 you welcome :) – Mr. Alien May 03 '13 at 07:46
  • That edit was probably because your answer doesn't match the question. In future, just stick to answering the question based on the code that is given. – BoltClock May 03 '13 at 09:41