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

Gutenberg: Cannot center-align image on certain themes #28756

Closed
KokkieH opened this issue Nov 21, 2018 · 44 comments
Closed

Gutenberg: Cannot center-align image on certain themes #28756

KokkieH opened this issue Nov 21, 2018 · 44 comments
Labels
[Closed] Not Reproducible Issue cannot be reproduced. [Feature Group] Appearance & Themes Features related to the appearance of sites. [Goal] Gutenberg Working towards full integration with Gutenberg [Type] Bug

Comments

@KokkieH
Copy link
Contributor

KokkieH commented Nov 21, 2018

Steps to reproduce

  1. Starting at URL: SITE_URL/wp-admin/post-new.php
  2. Add an image block and add an image
  3. If the image is full-width, resize it to a smaller size
  4. Set alignment to Center-aligned and publish post

What I expected

For the image to be center-aligned in the post

What happened instead

The image is left-aligned. Right-aligning the image works as expected, but selecting center-alignment causes the image to display left-aligned; or more accurate non-aligned as text from a succeeding paragraph block doesn't wrap as it does if the image is set to left-aligned.

Editing the post in the classic editor also indicates the image as non-aligned.

Screenshot / Video

Image in the editor:
edit_post_ kokkiestrialtestsite _wordpress

Published post:
image_align_ _kokkiestrialtestsite

What I see if I edit the post in the classic editor in WP-Admin:
edit_post_ kokkiestrialtestsite _wordpress

Viewing the block in HTML mode the class="aligncenter is applied to the image.

I'm not able to replicate this on a self-hosted site, so it appears to be an issue specifically with WordPress.com.

Context / Source

User report in the support forums

@KokkieH KokkieH added [Type] Bug [Goal] Gutenberg Working towards full integration with Gutenberg labels Nov 21, 2018
@KokkieH
Copy link
Contributor Author

KokkieH commented Nov 21, 2018

If I set the image to centered in the classic editor and update, it's correctly centered in the published version, but if I then edit the post in Gutenberg again it gives an invalid content warning:

edit_post_ kokkiestrialtestsite _wordpress

@supernovia
Copy link
Contributor

supernovia commented Nov 26, 2018

Another instance here, and few notes:

  • My own Gutenberg instance centers properly
  • If I copy the exact code from my Gutenberg instance to .com, it is misaligned on .com
  • Old wp-admin gives the figure a width; Gutenberg isn't. If I add a width to the figure, it centers.

Looks like we also add a display: block to the figure, so if we don't give it a width then it's gonna default to 100% and margin: auto won't really apply.

@laurelfulford
Copy link
Contributor

laurelfulford commented Nov 29, 2018

I think the display issues here may both be theme-related.

We've had a couple other reports, with Dara, Baskerville 2, and Manifest, where the issue is that the class .aligncenter has the style display: block, and that messes up the image block. The image block uses display: table, so once display: block overrides that, the styles that handle the centring no longer work.

@KokkieH the user that reported the issue in that thread was using Dara, which we've fixed. Do you happen to remember the other themes you recreated this with?

@supernovia Looking at https://silverwilderness.wordpress.com/2018/11/28/romance-in-ya-is-not-realistic/, I think the issue is coming from these styles in the theme: https://github.com/Automattic/themes/blob/master/libre-2/css/blocks.css#L78-L83. I'm going to make a new issue for that, for us to investigate.

If we can confirm all the themes used for reproducing this issue include some kind of problem styles instead of them coming from WP.com, we can close this issue :)

@KokkieH
Copy link
Contributor Author

KokkieH commented Nov 30, 2018

@laurelfulford, my test site where I confirmed this is coincidentally also on Dara, so I did not think to try this on different themes.

In that case, I've had a report in the WordPress.org forums as well, though I wasn't able to replicate this on a self-hosted site with Dara.

@laurelfulford
Copy link
Contributor

Thanks @KokkieH!

In that case, I've had a report in the WordPress.org forums as well, though I wasn't able to replicate this on a self-hosted site with Dara.

Okay, I think that's a good sign (or at least a sign in favour of the problem being a theme thing). The problem code in Dara's case was added with some other Gutenberg-related styles. We've been holding off submitting those updates to WP.org, at least until 5.0 is officially released, to see if we can catch some bugs (like this!) in advance.

@ghost
Copy link

ghost commented Dec 19, 2018

In Wordpress 5.01, this happens to me on all my sites where I use Gutenberg. Before upgrading to 5.0, it worked fine. Buttons and images simply do not center.

@desnum
Copy link

desnum commented Jan 30, 2019

Another case, on a site with the Baskerville 2 theme:

  • When the image is resized and centered in the editor, it shows as left-aligned in the frontend.
  • We added display:block; to the CSS as a temporary workaround.
  • hc-9976478

@spncr
Copy link

spncr commented Feb 14, 2019

Attache also has this issue:
https://wordpress.com/theme/attache

This fixes it, but probably not the best route:

.aligncenter{
  text-align: center;
}

@automattic-ian
Copy link

Also an issue in https://wordpress.com/theme/professional-business

investigating CSS workaround for now.

@Aurorum
Copy link
Contributor

Aurorum commented Mar 11, 2019

@automattic-ian I'm not able to reproduce an issue with centre image alignment at any screen ratio with that theme.

gsgfdgfdgfd

By any chance, are you referring to the Sophisticated Business theme? I've proposed a fix for that one at Automattic/themes#648, and it's being tracked at Automattic/themes#646.

@automattic-ian
Copy link

@torres126 it appears that I may have been mistaken and that this is a separate issue, it seems to only impact image galleries, not single images, as seen here:
image

Where you can see the class .aligncenter however the gallery is still pushed to the left.

@Aurorum
Copy link
Contributor

Aurorum commented Mar 11, 2019

Thanks @automattic-ian! I can reproduce, PR for that issue in Automattic/themes#660.

@katinthehatsite
Copy link
Contributor

Another site that was affected #1885592-zd

@mikeicode
Copy link

Another on #1847494-zen with tiled galleries, I provided this CSS to resolve it:

.entry .entry-content > .wp-block-jetpack-tiled-gallery.aligncenter, 
.entry .entry-summary > .wp-block-jetpack-tiled-gallery.aligncenter {
	margin: 0 auto;
}

@Aurorum
Copy link
Contributor

Aurorum commented Mar 17, 2019

@katinthehatsite @mikeicode Just out of curiosity, which theme(s)?

@mikeicode
Copy link

@torres126

Just out of curiosity, which theme(s)?

Professional Business

@katinthehatsite
Copy link
Contributor

katinthehatsite commented Mar 21, 2019

@torres126 For my case, it was theme Veni: https://wordpress.com/theme/veni

@reginabally
Copy link

Another issue reported in 1988165-zen for [Port theme](https://wordpress.com/theme/port].

@carinapilar
Copy link

I had another report on 12365791-hc where class="size-full wp-image-902 aligncenter" wasn't working on the Classic Editor. I had to add a p tag for the center alignment to work. Site uses the Boardwalk theme.

@aleone89
Copy link

aleone89 commented Jun 28, 2019

Another report in #13689395-hc

Theme - Baskerville 2.

I employed temp solution seen in GH-403

@nathalieflower
Copy link

I seem to be having this issue in the October theme. from playing with the css the only way I can get images to centre is at row level and by removing the display:flex, which isn't ideal

@KokkieH
Copy link
Contributor Author

KokkieH commented Jul 4, 2019

@nathalieflower I think you might be in the wrong repository. This issue is specifically regarding an issue with the block editor and some specific themes on WordPress.com, and October is not a theme offered on WordPress.com.

It would probably be best to contact support for your theme directly about this, as if it's a theme issue, a fix we apply on WordPress.com won't have any effect on your theme.

@carinapilar
Copy link

Another report for the Veni theme, on 15730086-hc.

@michaelswengel
Copy link

Same issue here with Sydney.

@michaelswengel
Copy link

Just tested on two of my sites running the same versions of everything. Same issue. This needs to be fixed.

@michaelswengel
Copy link

Testing further with various themes, this does appear to be a Gutenberg issue, not a theme issue. I can set an image to align right, and it does. Aligning center does nothing. Please fix this.

@Aurorum
Copy link
Contributor

Aurorum commented Oct 4, 2019

Unless something has changed recently (which I'm pretty sure it hasn't), then this is still a theme issue that generally needs fixing in individual themes. Sydney isn't a theme available on WordPress.com though, and it's probably best to contact the developer of that theme, since any changes to WordPress.com won't have an impact on that.

@michaelswengel
Copy link

michaelswengel commented Oct 4, 2019 via email

@michaelswengel
Copy link

michaelswengel commented Oct 4, 2019 via email

@Aurorum
Copy link
Contributor

Aurorum commented Oct 4, 2019

I use the Harmonic theme on WordPress.com. I can test Sydney on a self-hosted site at some point tomorrow to see if I can reproduce it, but for now, virtually no theme seems to still have this issue.

@michaelswengel
Copy link

michaelswengel commented Oct 4, 2019

@Aurorum, I don't think it's a theme issue.

I just tested with Twenty Nineteen, SmartTheme, Sydney, Twenty Fifteen, Twenty Seventeen, Twenty Sixteen, OceanWP.

It's not a theme problem.

This is across multiple WP installations. Everything up to date. Various themes.

@michaelswengel
Copy link

This is the code of an image that will not center:

<div class="wp-block-image"><figure class="aligncenter"><img src="https://listbootcamp.com/wp-content/uploads/2019/10/email-click-through-rate.png" alt="Example email CTR in GetResponse" class="wp-image-707"/><figcaption>Example email CTR in GetResponse</figcaption></figure></div>

Now, if I add <center></center> tags, it centers. Gutenberg does not center.

@michaelswengel
Copy link

michaelswengel commented Oct 4, 2019

Ok. Update. It's not a theme issue, but for me at least it was an Elementor issue. It appears Elementor is overriding Gutenberg's alignment. So I added this CSS:

.elementor .elementor-widget .wp-block-image .aligncenter { margin-left: auto; margin-right: auto; }

That seems to have fixed it for me. So it looks like something Elementor needs to fix.

@carinapilar
Copy link

Got another report on 2602696-zen with the Cubic theme.

@italocjs
Copy link

Ok. Update. It's not a theme issue, but for me at least it was an Elementor issue. It appears Elementor is overriding Gutenberg's alignment. So I added this CSS:

.elementor .elementor-widget .wp-block-image .aligncenter { margin-left: auto; margin-right: auto; }

That seems to have fixed it for me. So it looks like something Elementor needs to fix.

This has fixed for me too, add this line into "Appearance > Customize > Additional CSS"
i'm using JupiterX theme

@carinapilar
Copy link

Got another report on 17773353-hc with the Didi theme, now on a Video block.

@lancewillett
Copy link
Contributor

lancewillett commented Mar 19, 2020

I've run into this a few times on internal Automattic P2 sites; where the P2 Breathe theme existing CSS doesn't seem to correctly center the image as expected — and also the image caption itself wasn't centered; which should be a basic theme style.

@ianstewart
Copy link
Contributor

@lancewillett I reviewed all our free themes on WP.com and found these issues …

Automattic/themes#1856

@sourourn
Copy link

sourourn commented Apr 6, 2020

Another one reported here: #15799442-hc
User has a third party theme: logpixiecassidy

When you center align an image, it looks left aligned in the editor but it does display as center align on the front end.

Screen Shot 2020-04-06 at 14 07 54
Screen Shot on 2020-04-06 at 14-07-19

@thesacredpath
Copy link

There is a related issue happening in the editor. Reported on site with Independent Publisher 2 and also with Canard. Both are simple sites.

Steps to reproduce

  1. Starting at URL: Site > Pages > Add New
  2. Add an image block and add an image
  3. Set image to medium size
  4. Set image for center alignment
  5. Resize image larger or smaller using resize handle

What I expect

Image to remain center aligned in editor window and at new size

What happened

Image jumps to left aligned in editor, but if you preview the page or post, it will show correctly as center aligned.

Independent Publisher 2 ticket: 2867721-zen
Canard ticket: 2859492-zen

@davipontesblog davipontesblog changed the title Gutenberg: Cannot center-align image Gutenberg: Cannot center-align image on certain themes Jun 10, 2020
@nerdysandy nerdysandy added the [Feature Group] Appearance & Themes Features related to the appearance of sites. label Feb 10, 2021
@obenland
Copy link
Member

obenland commented Mar 1, 2021

This seems to have been fixed by WordPress/gutenberg#21167. I couldn't reproduce it with Baskerville 2 or Dara.

Please feel free to re-open if this error re-appears or can be reliably reproduced.

@obenland obenland closed this as completed Mar 1, 2021
@obenland obenland added the [Closed] Not Reproducible Issue cannot be reproduced. label Mar 1, 2021
@carinapilar
Copy link

Please feel free to re-open if this error re-appears or can be reliably reproduced.

@obenland, it might be theme-related, but I can still replicate the one I reported here.

With the Didi theme, create a new page using the "Front Template", the issue happens with a Vimeo or Youtube block, even though it has aligncenter. Here's a screenshot:

VimeoYoutubeCenterAlignmentIssue

@obenland
Copy link
Member

obenland commented Mar 1, 2021

Yes, it looks to be a theme issue with that page template

@carinapilar
Copy link

carinapilar commented Mar 1, 2021

Thanks for checking, @obenland! I have reported on the theme's repo. 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Closed] Not Reproducible Issue cannot be reproduced. [Feature Group] Appearance & Themes Features related to the appearance of sites. [Goal] Gutenberg Working towards full integration with Gutenberg [Type] Bug
Projects
None yet
Development

No branches or pull requests