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

Image Block: Image with aligncenter class no longer centered when used in a nested block #39291

Closed
ocean90 opened this issue Mar 8, 2022 · 2 comments · Fixed by #39422
Closed
Assignees
Labels
[Block] Image Affects the Image Block [Feature] Themes Questions or issues with incorporating or styling blocks in a theme. [Type] Bug An existing feature does not function as intended

Comments

@ocean90
Copy link
Member

ocean90 commented Mar 8, 2022

Description

When you add an image block into a group or column and set the alignment to center the image is no longer centered. It's only centered if the block is added on the top-level.

This was likely introduced by #38613 and/or #38657 while the top-level alignment is working due to changes in #38947.

This style is now no longer applied:

.aligncenter {
margin-left: auto;
margin-right: auto;
}

Only this, which has no effect:

&.aligncenter {
text-align: center;
}

@youknowriad, @jasmussen What would be the correct fix here?

Step-by-step reproduction instructions

  1. Add a group block, set some background color
  2. Add an image block into the group block
  3. Resize the image so it's smaller than the group block width
  4. Change image alignment to center
  5. Notice that the image is not centered

Screenshots, screen recording, code snippet

Environment info

  • Gutenberg 12.7 and trunk

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

@ocean90 ocean90 added [Block] Image Affects the Image Block [Type] Bug An existing feature does not function as intended [Feature] Themes Questions or issues with incorporating or styling blocks in a theme. labels Mar 8, 2022
@ocean90 ocean90 changed the title Image Block: Image no longer centered when used in a nested block Image Block: Image with aligncenter class no longer centered when used in a nested block Mar 8, 2022
@youknowriad
Copy link
Contributor

I think we need to add a generic aligncenter style to the "flow" layout (like we do for left/right alignments). Potentially we could remove the styles that are specific to the image block if we can (or keep them for classic blocks only)

@ocean90
Copy link
Member Author

ocean90 commented Mar 9, 2022

But since aligncenter now also has display: table assigned, setting margin has no effect on the element. It needs to be display: block to make it work but that again breaks the caption if set. Am I missing something?

I guess I did something wrong when I tried it the first time. margin-left/margin-right will work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Image Affects the Image Block [Feature] Themes Questions or issues with incorporating or styling blocks in a theme. [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants