$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 - Override theme style rule in Gutenberg|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 - Override theme style rule in Gutenberg

matteradmin9PV0评论

I have a theme that adds the following CSS rule inline through the Customizer to style the hover state of links in post content:

.entry-content a:hover {
    color: <color selected in the Customizer>;
}

I'm adding support for Gutenberg in my theme and I'm having some issues with the link button block. The previous rule is overriding the following default core block style rule that applies the same link button color selected in Gutenberg for the button active, focus and hover states:

.wp-block-button__link:active,
.wp-block-button__link:focus,
.wp-block-button__link:hover {
    color: inherit;
}

Checking the Inspector, I see that the last rule applied is the first one instead of the second one, which I thought it was more specific. That means that the link button color selected in Gutenberg is not honored.

Any ideas on how to fix this?

Thanks in advance

I have a theme that adds the following CSS rule inline through the Customizer to style the hover state of links in post content:

.entry-content a:hover {
    color: <color selected in the Customizer>;
}

I'm adding support for Gutenberg in my theme and I'm having some issues with the link button block. The previous rule is overriding the following default core block style rule that applies the same link button color selected in Gutenberg for the button active, focus and hover states:

.wp-block-button__link:active,
.wp-block-button__link:focus,
.wp-block-button__link:hover {
    color: inherit;
}

Checking the Inspector, I see that the last rule applied is the first one instead of the second one, which I thought it was more specific. That means that the link button color selected in Gutenberg is not honored.

Any ideas on how to fix this?

Thanks in advance

Share Improve this question asked Feb 20, 2019 at 7:21 leemonleemon 2,0284 gold badges25 silver badges51 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

.entry-content a:hover is more specific than .wp-block-button__link:hover.

According to the rules of specificity, the first selector contains 2 class selectors (.entry-content and :hover), and 1 type selector (a), for a specificity score of 0,0,2,1.

The second selector, on the other hand, contains 2 class selectors (.wp-block-button__link and :hover), and no type selectors, for a score of 0,0,2,0.

It wasn't clear to me from your question where exactly the second set of selectors was coming from, but assuming that you can't edit them, the solution would be to exclude Gutenberg buttons from your original selector. You can do this with the :not pseudo class:

.entry-content a:not(.wp-block-button__link):hover {
    color: <color selected in the Customizer>;
}

Now your Customizer-selected colour will only apply to links that are not block editor/Gutenberg buttons.

Post a comment

comment list (0)

  1. No comments so far