Reduce specificity of * variant #14056
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR reduces the specificity of the * variant so that classes directly on the child elements take precedence over the styles applied by the parent.
Previously a utility like
*:flexwould generate this CSS:This selector has a specificity of
0,1,0, which is the same as the specificity for a bare utility class likeflex,block, orgrid.Because variants always appear later in the CSS file than bare utilities, this means that given this HTML, the
gridclass on the child element would have no effect:After this PR, the
*:flexutility generates this CSS instead:This selector has a specificity of
0,0,0, so even though it appears later in the CSS, a bare utility with a specificity of0,1,0will still take precedence.This is something we wanted to do when we first introduced the
*variant in the v3 series, but couldn't because having such a low specificity meant that styles in Preflight would take precedence over utilities like*:flex, which is not would anyone would want.We can make this change for v4 because now all of Preflight is wrapped in a dedicated
@layer, and rules from later layers always take precedence over rules from earlier layers even if the rule in the later layer has a lower specificity.