Skip to content
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

Open
3 tasks done
philbuchanan opened this issue Aug 9, 2021 · 3 comments

Comments

@philbuchanan
Copy link
Task lists! Give feedback

@philbuchanan philbuchanan commented Aug 9, 2021

Is there an existing issue for this?

  • I have searched the existing issues

Have you tried deactivating all plugins except Gutenberg?

  • I have tested with all plugins deactivated.

Have you tried replicating the bug using a default theme e.g. Twenty Twenty?

  • I have tested with a default theme.

Description

When you add "layout": { "contentSize": "800px" } to the theme.json file, it adds the following CSS to the editor:

.editor-styles-wrapper .edit-post-visual-editor__post-title-wrapper > *, 
.editor-styles-wrapper .block-editor-block-list__layout.is-root-container > * {
    max-width: 773px;
    margin-left: auto !important;
    margin-right: auto !important;
}

If you add a block with alignfull it resets the width with max-width: none; but the margin-left and right which are set as such:

.editor-styles-wrapper .block-editor-block-list__layout.is-root-container > .wp-block[data-align=full] {
    margin-left: -8px;
    margin-right: -8px;
}

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 to alignfull 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

@annezazu
Copy link
Contributor

@annezazu annezazu commented Aug 9, 2021

cc @nosolosw in case you have thoughts here :)

@nosolosw
Copy link
Member

@nosolosw nosolosw commented Aug 10, 2021

@youknowriad would know best about layout things.

@youknowriad
Copy link
Contributor

@youknowriad youknowriad commented Aug 10, 2021

!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 margin: auto but we failed so far.

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants