gutenberg icon indicating copy to clipboard operation
gutenberg copied to clipboard

Image block margin/gap is overridden in the backend [Gutenberg 14 RC2]

Open slpy9 opened this issue 4 years ago • 5 comments

Description

Block gap is being overridden on the backend.

EDIT: I just corrected the order in which the styles are applied, sorry!

Backend styles:-

.editor-styles-wrapper .is-layout-constrained > * + * {
  margin-block-start: 80px; // <-- overridden
  margin-block-end: 0;
}
.editor-styles-wrapper .wp-block-image { 
  margin: 0 0 1em 0;
}

Frontend styles:-

body .is-layout-constrained > * + * {
  margin-block-start: 80px; // <-- working correctly
  margin-block-end: 0;
}
.wp-block-image {
  margin: 0 0 1em 0;
}

Step-by-step reproduction instructions

  1. Add a block
  2. Add an image beneath that block
  3. Check there is a top margin on the image block in the editor
  4. Check if the margin exists on the frontend

Screenshots, screen recording, code snippet

image

Environment info

  • WordPress 6.0.1, Gutenberg 14 RC2, Twenty Twenty-Two / Blank Theme
  • Chrome / Firefox
  • Desktop with Windows 10

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

slpy9 avatar Aug 25 '22 18:08 slpy9

I just refreshed my memory a bit on selector specificity.. I believe the issue is that this .is-layout-constrained > * + * has the same specificity as .wp-block-image, and since the .wp-block-image rule is applied later in the document, it's overriding the block gap margins.

slpy9 avatar Aug 25 '22 18:08 slpy9

Thanks for reporting this. I could reproduce it: Screen Shot 2022-08-30 at 2 57 12 pm

@andrewserong mentioned that the margin is specified in the block.json of the image block: https://github.com/WordPress/gutenberg/blob/b47a77df5632f3ed476a53337f475e0e2f5b074c/packages/block-library/src/image/block.json#L104-L108

talldan avatar Aug 30 '22 05:08 talldan

Hey thanks, I'm glad you found where it's coming from, I tried searching through the repository but gave up in frustration.

I think there are some other blocks affected by that style too.

slpy9 avatar Aug 30 '22 05:08 slpy9

I shared some additional context in https://github.com/WordPress/gutenberg/pull/41689#issuecomment-1220674662.

jasmussen avatar Aug 30 '22 06:08 jasmussen

Proposed fix here: https://github.com/WordPress/gutenberg/pull/43792

scruffian avatar Sep 01 '22 19:09 scruffian