-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using "layout" in theme.json adds margin-left and -right: auto with !important to full width elements #33956
Comments
cc @nosolosw in case you have thoughts here :) |
@youknowriad would know best about layout things. |
!important is unfortunately necessary here because left/right margins applied to children blocks using the margin UI for instance (non aligned) shouldn't apply because the block should remain centered in the "content area". We tried other solutions to "center" blocks without relying on That said, the negative margins above are added by the editor itself, I think adding important there might be an acceptable stop gap fix for now (for full aligned blocks). |
I’m not sure if this is on the roadmap but in the future how will we deal with site designs where the content area needs to be aligned to the left or right? It seems it should be possible to add a "contentAlignment" parameter to theme.json. Maybe something like this could go in theme.json:
And then it could output something like this:
Visual example: |
I've been digging a bit and have come up empty. I'm curious how we arrived to using the
To output a bunch of these inline styles on the frontend: It seems like it would be a bit easier to work with the I would then allow theme authors to opt in to using
Possibly related Issues: |
Actually, @keithdevon already proposed a similar approach in #36135 👏 |
I am with @allancole here #33956 (comment). I think for full flexibility we need a separation of width and alignment. We then obviously need two controls on the blocks. width: ['content', 'wide', 'full']
|
Updating the CSS examples since they have changed since the issue was created. Current CSS for regular width group block without alignment, front:
Editor:
Site editor, full width enabled on nested group:
|
With the new
|
Is this issue still valid? The description states that margins with |
I'm going to go ahead and close this one as fixed; please feel free to reopen if there's any outstanding issue! |
Is there an existing issue for this?
Have you tried deactivating all plugins except Gutenberg?
Have you tried replicating the bug using a default theme e.g. Twenty Twenty?
Description
When you add
"layout": { "contentSize": "800px" }
to the theme.json file, it adds the following CSS to the editor:If you add a block with
alignfull
it resets the width withmax-width: none;
but the margin-left and right which are set as such:cannot be overridden due to the
!important
.The result is an extra space of 8 pixels on each side of the editor.
Step-by-step reproduction instructions
See above.
Expected Behavior
Generally, I think the use of
!important
should be avoided since it makes it nearly impossible to override styles. Specifically, in this case, I'm not sure why the!important
is necessary at all. I would expect the-8px
margins to be applied toalignfull
elements.Current Behavior
See above.
Screenshots or screen recording (optional)
No response
Code snippet (optional)
No response
WordPress Information
WordPress 5.8
Gutenberg Information
Not using the Gutenberg plugin.
What browsers are you seeing the problem on?
Firefox, Chrome, Safari, Microsoft Edge
Device Information
No response
Operating System Information
No response
The text was updated successfully, but these errors were encountered: