Skip to content

Commit

Permalink
Alignment styles: Centre blocks using grid not margins (#32231)
Browse files Browse the repository at this point in the history
* Alignment styles: Centre blocks using flex not margins

* add border-box so that padding doesn't make blocks wider

* Use grid instead of flex

* Update lib/block-supports/layout.php

Co-authored-by: Ari Stathopoulos <[email protected]>

Co-authored-by: Ari Stathopoulos <[email protected]>
  • Loading branch information
scruffian and aristath authored May 27, 2021
1 parent 4fb9b2a commit fb7cb48
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
10 changes: 7 additions & 3 deletions lib/block-supports/layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,14 @@ function gutenberg_render_layout_support_flag( $block_content, $block ) {

$style = '';
if ( $content_size || $wide_size ) {
$style = ".wp-container-$id > * {";

$style = ".wp-container-$id { display: grid; }";

$style .= ".wp-container-$id > * {";
$style .= 'box-sizing: border-box;';
$style .= 'justify-self: center;';
$style .= 'max-width: ' . esc_html( $all_max_width_value ) . ';';
$style .= 'margin-left: auto !important;';
$style .= 'margin-right: auto !important;';
$style .= 'width: 100%;';
$style .= '}';

$style .= ".wp-container-$id > .alignwide { max-width: " . esc_html( $wide_max_width_value ) . ';}';
Expand Down
9 changes: 7 additions & 2 deletions packages/block-editor/src/components/block-list/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,15 @@ export function LayoutStyle( { selector, layout = {} } ) {
let style =
!! contentSize || !! wideSize
? `
${ selector } {
display: grid;
}
${ appendSelectors( selector, '> *' ) } {
box-sizing: border-box;
justify-self: center;
width: 100%;
max-width: ${ contentSize ?? wideSize };
margin-left: auto !important;
margin-right: auto !important;
}
${ appendSelectors( selector, '> [data-align="wide"]' ) } {
Expand Down

0 comments on commit fb7cb48

Please sign in to comment.