Ágota Horváth Ágota Horváth - 1 month ago 5
CSS Question

How to apply format depending on absence of a CSS class?

If I would like to format an element that has a given class, sometimes (very rare) I use:

.beigeButton[class~="enabledButton"] {

}


What if I want to give properties to an element only when it does NOT contain the given string?
This does not work:

.beigeButton[class!="enabledButton"] {

}


How can I do that?

Answer

Use :not:

.beigeButton:not(.enabledButton)