:not(:empty) CSS Selector Not Working
The :not(:empty) selector fails to target input fields with text content. This issue arises when combining multiple selectors, particularly :not(:empty):not(:focus):invalid. Removing :not(:empty) resolves the issue, but using it within :not() seems inconsistent.
To clarify, the :empty selector indicates elements with no child nodes. In the context of input elements, this includes those without text content. However, the HTML definition classifies input elements as void, meaning they are inherently empty.
As stated in the Selectors spec, ":empty pseudo-class represents an element that has no children at all." This includes input elements regardless of their value, so input:not(:empty) effectively never selects anything in valid HTML.
While CSS alone cannot dynamically style empty input fields, you can target initially empty fields using [value=""] or :not([value]) to design appropriate initial states.
The above is the detailed content of Why Doesn't :not(:empty) Work for Input Fields with Text?. For more information, please follow other related articles on the PHP Chinese website!