When using InnerBlocks so you can nest parent/child blocks you end up with additional HTML (in the editor) wrapping the child elements like so:
<div class="PARENT">
<div class="block-editor-inner-blocks">
<div class="block-editor-block-list__layout">
<div class="block-editor-block-list__block wp-block is-selected">
<div class="CHILD"></div>
</div>
</div>
</div>
</div>
This causes a bit of a mess if using things like flexbox or grid on the parent element because it means the styles will instead apply to the .block-editor-inner-blocks
instead.
e.g.
.PARENT {
display: grid;
grid-template-columns: repeat(3, minmax(0, 33%));
}
To get around this I've found myself having to do hacky overrides or write two different sets of CSS to handle the extra HTML that wraps the blocks in the editor:
.PARENT,
.PARENT .block-editor-block-list__layout {
display: grid;
grid-template-columns: repeat(3, minmax(0, 33%));
}
.editor-styles-wrapper .PARENT {
display: block; /* remove grid in editor */
}
Is there a solution to avoid this? Or are you stuck with two sets of CSS or overrides when viewed inside the editor?
useBlockProps
anduseInnerBlockProps
that can be used to eliminate the bulk of that markup if not all of it