In CSS Selectors Level 3, parsing errors lead to the discarding of rules containing invalid selectors. This behavior has been implemented consistently by browsers for years, ensuring predictable error handling.
The rationale for discarding entire rules is multi-faceted:
To illustrate the issue, here is an example rule:
#menu li.last, #menu li:last-child { ... }
In browsers like IE8 that lack :last-child support, the entire rule is discarded due to an invalid selector despite the validity of the first selector.
Dropping unrecognized selectors without discarding the rule was considered. However, it introduced potential risks:
Some layout engines may exhibit differing behavior. WebKit ignores prefixed selectors, while others disregard the entire rule. These deviations emphasize the potential for cross-browser inconsistencies if error-handling rules are revised.
The above is the detailed content of Why Are CSS Rules Dropped Due to Invalid Selectors?. For more information, please follow other related articles on the PHP Chinese website!