gutenberg icon indicating copy to clipboard operation
gutenberg copied to clipboard

Unexpected CSS margins added to container blocks

Open iandunn opened this issue 5 years ago • 3 comments

Description

As of #33812, spacing gaps are automatically applied to FSE themes. That can cause unexpected results for theme authors in some situations.

we don't have answers for all the use cases yet... I'd love to learn mode about the use-cases to be able to come up with the best abstractions that solve this

  • https://github.com/WordPress/gutenberg/pull/33812#issuecomment-910385740

I thought it'd be helpful to have an issue where we can post those use cases. Please add comments here when you encounter one.

Step-by-step reproduction instructions

Both of these are with the default 24px gap, rather than defining one in theme.json.


.site-header is given a margin-top because .skip-link precedes it:

<div class="wp-site-blocks">
	<a class="skip-link screen-reader-text" href="#wp--skip-link--target">Skip to content</a>

	<header class="wp-container-613a423080be0 wp-block-group site-header">

I expected it to have none, since it's the site header and the preceding element is visually hidden. maybe fix by adding a not(.screen-reader-text) selector. that wouldn't catch everything, but it might get most.


More broadly, child elements of .site-header and .site-footer are given margin-top, but I'd expect only post content and the sidebar to be affected. I don't really see a logical relationship in those areas like there is with elements inside post content.

Maybe in general-purpose themes everything should be affected, but not in a custom theme where the header/footer are locked.

( previously mentioned by @chthonic-ds )

Screenshots, screen recording, code snippet

No response

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

iandunn avatar Sep 09 '21 20:09 iandunn

Would it be possible to have an option on all blocks that would allow the block gap to be toggled off in those instances where it is not required?

If that was an option, templates and parts could define when a particular block would have the block gap off, e.g. something like "hasBlockGap":false

<!-- wp:group {"tagName":"header","className":"site-header","hasBlockGap":false} -->
<header class="wp-block-group site-header">

Sandstromer avatar Sep 10 '21 09:09 Sandstromer

I expected it to have none, since it's the site header and the preceding element is visually hidden. maybe fix by adding a not(.screen-reader-text) selector. that wouldn't catch everything, but it might get most.

Good point on this one, this one is more like a bug, maybe we can render the "skip-link" outside the "wp-site-blocks"?

youknowriad avatar Sep 15 '21 11:09 youknowriad

I noticed that in 2025 the skip link is now rendered outside of the wp-site-blocks container, so this seems fixed.

youknowriad avatar Dec 01 '25 13:12 youknowriad