-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Remove block alignment wrapper in editor #33142
Description
What problem does this address?
In the editor, blocks with alignment (e.g. Wide, Full) are wrapped in a div with the .wp-block class and a data-align attribute.
All other block specific classes are then added to a child of this block.
<div class="wp-block" data-align="full">
<div style="background-color: rgb(185, 204, 70);" class="wp-block-group has-brand-green-background-color has-background" ...>...</div>
</div>
This means that selectors such as .wp-block-group.alignfull.has-background have no effect in the editor.
This leads to two problems (that I know of):
- Frontend theme styles often break and have to be recreated with specific editor stylesheets.
- Sometimes, useful selector rules, particularly nth-of-type, nth-child, and adjacent operators, cannot be used in the editor.
For example, if you want to remove margins between two full-width groups with background colours you might do something like this:
.wp-block-group.alignfull.has-background + .wp-block-group.alignfull.has-background {
margin-top: -50px;
}
This has no effect in the editor as there is no elelment that can contain all of these classes - they are split onto two levels of div.
Do we need the wrapper with .wp-block and the data-align? Blocks with no alignment don't have a wrapper, so I'm assuming it isn't used as a hook for the editor UI.
What is your proposed solution?
Remove the <div class="wp-block" data-align="full"> div and add the wp-block and alignment classes to the block level element.
E.g. <div class="wp-block wp-block-group has-background alignfull ..." ...>...</div>
If needed, the data-align attribute can be added in addition to the alignment class.
E.g. <div class="wp-block wp-block-group has-background alignfull ..." data-align="full" ...>...</div>