Sometimes, we want to write a CSS selector selecting elements not having a certain class or attribute.
In this article, we’ll look at how to write a CSS selector selecting elements not having a certain class or attribute.
How to write a CSS selector selecting elements not having a certain class or attribute?
To write a CSS selector selecting elements not having a certain class or attribute, we use the :not pseudoclass.
For instance, we wrirew
:not(.printable) {
/* Styles */
}
:not([attribute]) {
/* Styles */
}
to select the elements that don’t have the printable class with
:not(.printable) {
/* Styles */
}
And we select the elements that don’t hjave the attribute
attribute with
:not([attribute]) {
/* Styles */
}
Conclusion
To write a CSS selector selecting elements not having a certain class or attribute, we use the :not pseudoclass.