-
Notifications
You must be signed in to change notification settings - Fork 689
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[selectors] :visible / :hidden #7489
Comments
While pseudo-elements have limited the set of properties that apply, we've never limited the properties for pseudo-classes before, and it's a somewhat different concept, since the limitation has to apply based on the selector used to match the rule, rather than the simpler model of applying to the thing (pseudo-element) being matched. |
Yeah, we can't meaningfully limit the set of properties you can apply via a pseudo-class. Not only is it actually a completely distinct and more complicated subject due to what you're filtering by, it doesn't extend. If you have pseudo-classes :foo and :bar that can have their matching affected by properties, so you prevent rules using :foo from setting property So that idea is just permanently, unfixably dead in the water forever. If you want selectors that can be affected by properties/layout, you must build them on the same model as |
Could this be the case here? |
To answer myself here: No, this is not feasible and is explained in the wiki why |
There is a mechanism to check an element’s visible status:
Element.checkVisibility
. I see some use-cases for a:visible
selector, which would match elements whoseElement.checkVisibility
check returnstrue
.:hidden
would go hand in hand with that and select the opposite set of elements.An example would be to “style the first visible item in a list of items that can be dynamically filtered”. To target said element, the selector would be
:nth-child(1 of > :visible)
. Prior Art is jQuery’s:visible
selector, but don’t have any numbers on how much it was used.There are some considerations to keep in mind with such a selector, though:
:visible
? My hunch would be that it’s not very performant.:visible { opacity: 0; }
would make an element no longer visible, thus the selector would become unmatched.That second issue is a broader CSS issue which could be solved by limiting which CSS properties can be changed when such an element is targeted. Just like styling the pseudo
::first-line
and styling highlights are limited to a set of allowed properties, these:visible
/:hidden
selectors could have a disallow-list of properties:display
,opacity
, …Furthermore you wouldn’t be able to do anything really practical from a CSS point of view when targeting
:hidden
, but could use it indocument.querySelectorAll()
to select those elements for further processing.The text was updated successfully, but these errors were encountered: