Skip to content

Image block style - .is-style-rounded overrides my block style css #35151

Closed

Description

@romerocs

Description

I've created a custom block style for applying rounded corners to block images. However, after a recent WP core update I noticed my block styles were being overridden by the core block library css. It resets the border-radius for all block images to border-radius: inherit. So now I need to increase the specificity of my css in order to apply my styles. The high specificity of this css makes it difficult to apply custom styles and sets a precedent where I'm worried my custom styles will be overridden by a core update.

Is there a reason why the block image css wasn't simply written as .wp-block-image img { border-radius: inherit; }?

block-library/style.min.css

.wp-block-image:not(.is-style-rounded) img {
 border-radius:inherit
}

custom-block-styles.css

.is-style-custom-rounded-corners img {
  border-radius: #{$_border_radius};
}

PS, we use the rounded corner style on the site so removing it isn't an option.

Step-by-step reproduction instructions

  1. Create a custom block style for adding rounded corners
  2. Apply the custom block style to an image
  3. The custom block style may not work depending on its level of specificity (see description)

Screenshots, screen recording, code snippet

No response

Environment info

  • Wordpress 5.8.1

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

No

Activity

  1. added
    CSS StylingRelated to editor and front end styles, CSS-specific issues.
    on Sep 28, 2021
  2. markhowellsmead commented on Jan 25, 2022

    @markhowellsmead

    The :not() selector is being used in many places in core, which has a comparatively high specificity and is therefore increasingly difficult to override. The use of this technique needs to be reviewed by whomever (or by the team) is “in charge” of Core/Editor CSS.

    See also #36135, #35840, #34047, #29705, #17511.

  3. aaronrobertshaw commented on Aug 10, 2022

    @aaronrobertshaw
    Contributor

    This issue has been resolved via #31366, which leverages new feature level selectors for block supports to target the inner img. This meant the problematic style wasn't required anymore and was subsequently removed.

    I'll close this issue now however if you have any further concerns or questions, please let me know.

    Is there a reason why the block image css wasn't simply written as .wp-block-image img { border-radius: inherit; }?

    I believe this was because the suggested selector wouldn't allow custom border radii set by end users to take precedence.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    CSS StylingRelated to editor and front end styles, CSS-specific issues.[Block] ImageAffects the Image Block

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions