DEV Community

Discussion on: Is there a way to exclude elements with a particular default styling from a CSS selector?

Collapse
alvaromontoro profile image
Alvaro Montoro • Edited

You cannot target the internal styles of an element. So there's no way to do it exclusively with CSS unless: a) the styles are inline; or b) you use the hidden HTML attribute to hide elements instead of the CSS display: none.

To select all the elements that don't have an inline style of display: none, you could do something like:

/* You'd need to add different cases for different spaces. A pain. */
*:not([style*="display:none"i]) { ... }
Enter fullscreen mode Exit fullscreen mode

To select all the elements not hidden with the hidden attribute, you could do:

*:not([hidden]) { ... }
Enter fullscreen mode Exit fullscreen mode