Categories
CSS

How to write a CSS selector selecting elements not having a certain class or attribute?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *