$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>block editor - CSS Selector to override default theme.json custom properties in theme stylesheet|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

block editor - CSS Selector to override default theme.json custom properties in theme stylesheet

matteradmin9PV0评论

I need to specify some more finicky media query driven styles to override theme.json's default custom properties. Abbreviated example below. This example works, however I don't like that I have to use two selectors to make it work on both the front end and in the block editor.

:root {} doesn't work on the front end, as it is overridden by the default root: {} declarations in Wordpress' global-styles-inline-css, which load after the theme stylesheet.

:root body {} has enough specificity to work on the front end, but the editor doesn't have/recognize body.

Is there a single selector specific enough to work for both? Or should my theme stylesheet be enqueueing after global-styles-inline-css on the front end?

Example usage:

:root body, //for specificity on the front-end
:root { // for recognition in the block editor
    @media min-width(1020px){
        --wp--preset--font-size--xxl: 3.25rem;
        --wp--preset--font-size--xl: 2.75rem;
        --wp--preset--font-size--lg: 2.375rem;
        //etc.
    }
    // etc.
}

I need to specify some more finicky media query driven styles to override theme.json's default custom properties. Abbreviated example below. This example works, however I don't like that I have to use two selectors to make it work on both the front end and in the block editor.

:root {} doesn't work on the front end, as it is overridden by the default root: {} declarations in Wordpress' global-styles-inline-css, which load after the theme stylesheet.

:root body {} has enough specificity to work on the front end, but the editor doesn't have/recognize body.

Is there a single selector specific enough to work for both? Or should my theme stylesheet be enqueueing after global-styles-inline-css on the front end?

Example usage:

:root body, //for specificity on the front-end
:root { // for recognition in the block editor
    @media min-width(1020px){
        --wp--preset--font-size--xxl: 3.25rem;
        --wp--preset--font-size--xl: 2.75rem;
        --wp--preset--font-size--lg: 2.375rem;
        //etc.
    }
    // etc.
}
Share Improve this question edited Apr 28 at 11:51 fuxia 107k39 gold badges255 silver badges461 bronze badges asked Apr 28 at 2:22 StudioAlStudioAl 5161 gold badge4 silver badges15 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

You could try to increase specificity with something like html:root

html:root {
  @media (min-width: 1020px) {
    --wp--preset--font-size--xxl: 3.25rem;
    /* etc */
  }
}

Or you could get your styles to load after the global styles as an option as you mentioned if you want to leave it as just :root

Post a comment

comment list (0)

  1. No comments so far