-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Remove block alignment wrapper in editor #33142
Comments
Wait until you start fighting .is-root-container > :first-child,
.is-root-container > style:first-child + [class*=wp-block],
.is-root-container > [data-align]:first-child > [class*=wp-block]:first-child,
.is-root-container > .block-editor-block-list__block:first-child > :first-child,
.is-root-container > style:first-child + [data-align] > :first-child,
.is-root-container > [style*=hidden]:first-child + style + [data-align] > :first-child,
.wp-block-cover__inner-container > style:first-child + [class*=wp-block],
.wp-block-template-part > style:first-child + [class*=wp-block],
.wp-block-embed > .wp-block-embed,
.wp-block-spacer + [data-align] > :first-child,
.wp-block-group > [data-align]:first-child > :first-child,
.wp-block-group > style:first-child + .wp-block-group,
.wp-block-group > style:first-child + [data-align] > :first-child,
[data-align=full] + [data-align=full] > [class*=wp-block]:first-child,
[data-align=full] > [class*=wp-block]:first-child > [data-align=full]:first-child > [class*=wp-block]:first-child,
[data-align=full] + [style*=hidden] + [data-align=full] > [class*=wp-block]:first-child,
[data-align=full] + [style*=hidden] + style + [data-align=full] > [class*=wp-block]:first-child,
[data-align=full] + style + [data-align=full] > [class*=wp-block]:first-child,
[data-align=full] + style + style + [data-align=full] > [class*=wp-block]:first-child,
[data-align=full] + style + [style*=hidden] + [data-align=full] > [class*=wp-block]:first-child,
[data-align=full] + style + [style*=hidden] + style + [style*=hidden] + [data-align=full] > [class*=wp-block]:first-child {
margin-top: 0;
} |
After testing theme.json themes today, I noticed this wasn't an issue (though I couldn’t really nail it down). Are the standard block margins removed if a theme has a theme.json file? |
The I'm not sure what the standard block margins are. Margins for me are added by the theme. |
@justintadlock The wrapper is still there, but the default block margins are removed from themes with theme.json (per this PR #30375 I found). That's great for theme.json themes, but not for any current themes. :/ |
The source of default block margins doesn't really matter. As long as the For example, you can't kill margins for this: <div data-align="full">
<div class="wp-block-example"></div>
</div>
<div data-align="full">
<div class="wp-block-example"></div>
</div> With CSS like: .wp-block-example {
margin-top: 2rem;
}
.wp-block-example.alignfull + .wp-block-example.alignfull {
margin-top: 0;
} That CSS works on the front end because the HTML is this: <div class="wp-block-example alignfull"></div>
<div class="wp-block-example alignfull"></div> You can certainly do some weird and hacky workarounds to sort of make it work in the editor...until it doesn't. And, this is just the most basic of examples.
And, it's not all about margins. It can be any style rule -- for example, a theme author might want to add/remove bottom/top borders between siblings, alternate default background colors, or a million other things. |
Just to show a slightly more complex example, when multiple File blocks appear after one another, I want them to look like this: What I've done there is target However, if I add a "wide" alignment (or "full") to the File blocks, the There is a workaround for this very specific scenario, which is to add them all to the Group block without layout inheritance. |
I'm saying the default |
I've found targeting the > sibling, then adding a |
There would be because themes must still use margin, padding, or some other method to handle whitespace between elements. But, this ticket is not about the existence/non-existence of core default margins or even specifically about margins. It is about inconsistent markup between the front end and the editor. The editor markup is causing a situation where it is impossible to target sibling blocks of the same type (and related issues with Canceling margins is just an example and common use case.
Users should never have to micro-manage every block's spacing (at least those with wide/full alignment). They should have the choice, but themes need to be able to design a solid foundation and set up smart defaults for spacing and everything else (again, this ticket is not specifically about margins).
The |
@justintadlock I'm not discounting the need/issue, just providing context on how themes.json based themes are handling this. I'm finding more and more that the transition between pre and post theme.json themes will be a bit finicky for a while as we head further and further down this trail. |
After a bit of digging I found the original PR that introduced the new alignment wrappers. In the PR, @ellatrix states that:
In the code itslef there is a comment that states:
My questions are:
|
Seeing a decision made on this soon would be wonderful, if at all possible. I imagine a number of block-based/FSE themes are on the boil right now and not having to account for the This comment #23089 (comment) in the linked PR suggests it's possible to remove the |
It would be great if the I would expect the same exact classes ( |
I, too, have run into some trouble lately with the alignment wrappers. It seems like nearly every theme I've tried has trouble with styling the block editor... especially when it comes to alignments. One of the most popular (and frequently updated) themes right now, Astra, currently has tons of broken editor styles including alignments, and frankly, it's hard to blame them. Trying to support the block editor right now is a lot of extra work for themes right now, because it's a confusing mess of inconsistent markup and specificity hell. It would really be nice to see this get prioritized. The WYSIWYG-ness of the editor is the whole point, isn't it? All the major page builders have done a much better job at this, and while I understand why Gutenberg hasn't gotten there yet, it's nevertheless disappointing to see editor styling in its current state. It makes the editor feel broken and unfinished, despite all the wonderful improvements made since WP 5.0. I'm guessing the work on moving the edited content to an |
@ZebulanStanphill If it helps, #33142 describes a workaround for the current alignment issues in hybrid themes. |
To add to @ZebulanStanphill's comment . I'm relatively new to Gutenberg development, and one of my biggest challenges has been making sense of the editor HTML. I'm not sure i'd call it broken (i'd say its unfinished), but it definitely raises some eyebrows. When I stepped into Gutenberg, it promised this amazing sync between back and front end, which is there for the user, but the reality for a developer is different. We have to maintain 2 different stylesheets (and sometimes fight style.min.css 's opinionated styling). Since this (alignwide support) is at an experimental state, I hope it gets attention. |
This is a major problem for me too. It drives me crazy that I can't target the block. I wish |
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.
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):
For example, if you want to remove margins between two full-width groups with background colours you might do something like this:
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>
The text was updated successfully, but these errors were encountered: