-
Notifications
You must be signed in to change notification settings - Fork 4.8k
CSS Custom Properties on BODY lead to DOM inheritance issues #35840
Copy link
Copy link
Closed
Labels
CSS StylingRelated to editor and front end styles, CSS-specific issues.Related to editor and front end styles, CSS-specific issues.Global StylesAnything related to the broader Global Styles efforts, including Styles Engine and theme.jsonAnything related to the broader Global Styles efforts, including Styles Engine and theme.json[Feature] ThemesQuestions or issues with incorporating or styling blocks in a theme.Questions or issues with incorporating or styling blocks in a theme.[Type] BugAn existing feature does not function as intendedAn existing feature does not function as intended
Metadata
Metadata
Assignees
Labels
CSS StylingRelated to editor and front end styles, CSS-specific issues.Related to editor and front end styles, CSS-specific issues.Global StylesAnything related to the broader Global Styles efforts, including Styles Engine and theme.jsonAnything related to the broader Global Styles efforts, including Styles Engine and theme.json[Feature] ThemesQuestions or issues with incorporating or styling blocks in a theme.Questions or issues with incorporating or styling blocks in a theme.[Type] BugAn existing feature does not function as intendedAn existing feature does not function as intended
Type
Fields
Give feedbackNo fields configured for issues without a type.
Description
Classically, the assignment of CSS Custom Properties begins at the top-level (or "root") element through the use of
:root. This is common usage and allows the values to be inherited down through the DOM tree.(It is also one of the methods by which the popular IE11 polyfill
css-vars-ponyfillworks. I realise that IE11 support is being dropped from WordPress Core, but solving the inheritance issue would also allow this ponyfill to work again with no additional effort.)Gutenberg adds the generated CSS Custom Properties to the
bodyelement, and not:root, through applyingglobal-stylesusing thewp_add_inline_stylefunction. This leads to issues where third-party CSS authors connect the generated properties to their own Custom Properties on:root. The generated properties are not available at the top root level, and so the standard CSS cascade (inheritance) doesn't work.Recommendation (and request!): apply the global CSS Custom Properties to
:root, notbody.Step-by-step reproduction instructions
Screenshots, screen recording, code snippet
Here's a Codepen example of the code above: https://codepen.io/permanenttourist/pen/oNeYgVP?editors=1100
Environment info
Please confirm that you have searched existing issues in the repo.
Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Yes