Problem/Motivation

Upload an image in the editor and set its alignment to Right.
Alignment
View the page — the image still appears left-aligned.

Proposed resolution

I noticed that the alignright class is applied to the parent container along with the wp-block-image class, but in the CSS, the alignright class is being targeted on the child tag instead.
We have to update the CSS to target the alignleft, alignright, and aligncenter classes properly.

Please see the screenshots for reference.

DOM
CSS

Remaining tasks

User interface changes

API changes

Data model changes

CommentFileSizeAuthor
#2 3568931-1.patch456.83 KBkeshavv
css.png201.5 KBkeshavv
dom_view.png193.57 KBkeshavv
alignment.png48.44 KBkeshavv

Comments

keshavv created an issue. See original summary.

keshavv’s picture

StatusFileSize
new456.83 KB

Created a patch to fix it by updating the CSS

marcofernandes’s picture

The vendor CSS in the module (block-library/blocks/image/style.css) matches upstream WordPress Gutenberg and is working as designed. It's best if themes provide their own alignment styles for .alignleft, .alignright, and .aligncenter.
Maybe we should have highlighted a bit more or be more detailed on the documentation but it's there: https://www.drupal.org/docs/contributed-modules/gutenberg/best-practices...

This is a more complex issue than just patching the css. For starters, Gutenberg module includes the style from block-library on the frontend when this style is only to be used in the editor. The alignment classes should be built on the fly (with cache mechanisms, ofc) via layout processor which implementation is incomplete in Drupal Gutenberg. Hopefully a fix it's on the way but no ETA yet.

marcofernandes’s picture

Status: Active » Closed (works as designed)

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.