Skip to content

Image & Cover Block SCSS inconsistent with Media&Text & Embed Block - Forces Theme Acrobatics #11234

Description

@timhibberd

Describe the bug
Image Block (.wp-block-image) & Cover Block (.wp-block-cover, .wp-block-cover-image) SCSS are setting the block width to 100% and the left / right margins to 0 in isolation from .alignfull / .alignwide. This forces the theme to go to unnecessary lengths to get the blocks to fit in containers that have margins due to the standard WordPress loading sequence of theme / plug-in css files since the block width and margins are given priority over the theme styles which are loaded earlier.

The Image Block & Cover Block inconsistently set max-width, width, and left / right margins relative to Media & Text Block and Embed Block. The latter two are a breeze for the theme to style. I'm not sure why the Image Block and Cover Block do not have SCSS configured the same as Media & Text Block and Embed Block w.r.t. Width, Max-Width, left / right margins.

Here is what it looks like in the theme...

Embed Block (Easy Fit into a container with margins):

image

Media & Text Block (Easy Fit into a container with margins):

image

Image Block (Not a natural fit in a container with margins...would need to use !important to override):

image

Cover Image Block (Not a natural fit in a container with margins...would need to use !important to override):

image

To Reproduce
Simply look in the SCSS file and the output CSS files. See screenshots above for clearer visual explanation.

Expected behavior
Left/right margins should only be set to 0 and the width set IF .alignwide or .alignfull is in play AND Gutenberg should consider carefully if it needs to style unqualified block classes at all. If all base block classes were always styled in the GB editor paired with a qualification class (never unqualified) then the theme can easily target any override if necessary because it always has targeting context. The unqualified base class is tough for the theme to target accurately in all cases without resorting to tricks or more complex overrides. For easier theme targeting GB could introduce a .noalignment class to complement the .alignwide and .alignfull. This provides a simple theme class targeting model because ALL the GB editor styling becomes contextually qualified which is easy to target in the theme. Yes...there are always CSS tricks to get the job done and, yes, we can register to override all the block styling...but it would be preferable not to when a small adjustment would make everything so much simpler.

For those of you shaking your heads going...no that won't work...I leave you with the following question...

The question to answer here is...if Media & Text Block and Embed Block don't need left / right 0 margin AND width on the unqualified block base class WHY does the Image Block & Cover Block need to. I can't see why they couldn't all be consistent. And, if I was to choose one of the two left / right 0 margin AND width styles for consistency...I would choose Media & Text Block and Embed Block style (i.e. no unqualified left / right 0 margin AND width).

So the following is hard for the theme to style without needing to register block override styling:

.wp-block-image { max-width: 100%; margin-bottom: 1em; margin-left: 0; margin-right: 0; }

The following is easy for the theme to style without needing to register block override styling:

.wp-block-image .alignfull { max-width: 100%; margin-bottom: 1em; margin-left: 0; margin-right: 0; }

Screenshots
See above

Desktop (please complete the following information):

  • OS: Windows
  • Browser Firefox
  • Version 63.0

Smartphone (please complete the following information):
Not tested

Additional context
Using core (5.0-beta2-43845. Gutenberg plug-in not active. This bug is a design issue not an operational issue. The issue applies within the current Gutenberg source code and, in-turn, the Core v5x source code.

Here, for example, is the Gutenberg Image Block SCSS showing that the 0 margin and 100% are NOT within the .alignfull context as I would suggest they should be. NOTE that the comment expresses qualification but the scss does not ( // This resets the intrinsic margin on the figure in non-floated, wide, and full-wide alignments. ):

image

CAVEAT: I defer to those who consider themselves CSS experts to wade in. Me...I'm happy to admit there are people who know CSS better than I. I think my suggestion is workable. I leave it to all you wiser CSS experts to judge...be kind :-)

Metadata

Metadata

Assignees

Labels

Needs TestingNeeds further testing to be confirmed.[Status] In ProgressTracking issues with work in progress

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions