Issue:
The CSS Selectors Level 3 specification mandates that rules containing invalid selectors be discarded. Why is this necessary instead of simply removing the unrecognized selector and keeping the rule set?
Rationale:
According to the CSS2.1 specification:
Even though the rest of the selector may look reasonable in CSS 2.1, the whole statement should be ignored if there is an error anywhere in the selector, because it's not known if the comma may acquire other meanings in future updates of CSS.
The CSS Selectors Level 4 specification introduces functional pseudo-classes that accept selector groups as arguments, such as :not(). This could lead to ambiguities in parsing, making it difficult for implementations to accurately handle invalid selectors without potential layout disruptions.
Additionally:
Therefore, disregarding rules with invalid selectors maintains consistency in error handling, ensures forward compatibility, and prevents potential layout issues.
The above is the detailed content of Why are CSS rules with invalid selectors discarded instead of just removing the invalid part?. For more information, please follow other related articles on the PHP Chinese website!