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?
In CSS, to exclude a particular class, we can use the pseudo-class :not selector also known as negation pseudo-class or not selector. This selector is used to set the style to every element that is not the specified by given selector. Since it is used to prevent a specific items from list of selected items.
Matches elements with an attr attribute whose value is exactly value or begins with value immediately followed by a hyphen. In the example below you can see these selectors being used. By using li[class] we can match any list item with a class attribute. This matches all of the list items except the first one.
To select elements with a specific class, write a period (.) character, followed by the name of the class. You can also specify that only specific HTML elements should be affected by a class. To do this, start with the element name, then write the period (.)
An element with nothing between its tags is empty. That includes if an element contains a code comment. And if the CSS for the element has generated content — as from a pseudo-element like ::before or ::after — it is also still considered empty.
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
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; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With