Skip to content

Commit

Permalink
Fix center aligned images styles (#39422)
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad authored Mar 15, 2022
1 parent 0ef399d commit 45c37fb
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
5 changes: 3 additions & 2 deletions lib/block-supports/layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ function gutenberg_get_layout_style( $selector, $layout, $has_block_gap_support
$style .= "$selector .alignfull { max-width: none; }";
}

$style .= "$selector .alignleft { float: left; margin-inline-start: 0; margin-inline-end: 2em; }";
$style .= "$selector .alignright { float: right; margin-inline-start: 2em; margin-inline-end: 0; }";
$style .= "$selector > .alignleft { float: left; margin-inline-start: 0; margin-inline-end: 2em; }";
$style .= "$selector > .alignright { float: right; margin-inline-start: 2em; margin-inline-end: 0; }";
$style .= "$selector > .aligncenter { margin-left: auto !important; margin-right: auto !important; }";
if ( $has_block_gap_support ) {
$gap_style = $gap_value ? $gap_value : 'var( --wp--style--block-gap )';
$style .= "$selector > * { margin-block-start: 0; margin-block-end: 0; }";
Expand Down
5 changes: 5 additions & 0 deletions packages/block-editor/src/layouts/flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ export default {
margin-inline-start: 2em;
margin-inline-end: 0;
}
${ appendSelectors( selector, '> .aligncenter' ) } {
margin-left: auto !important;
margin-right: auto !important;
}
`;

if ( hasBlockGapStylesSupport ) {
Expand Down
3 changes: 2 additions & 1 deletion packages/block-library/src/column/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"__experimentalDefaultControls": {
"padding": true
}
}
},
"__experimentalLayout": true
}
}
1 change: 1 addition & 0 deletions packages/block-library/src/image/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
margin-bottom: 0.5em;
}

// This is needed for classic themes where the align class is not on the container.
.aligncenter {
margin-left: auto;
margin-right: auto;
Expand Down

0 comments on commit 45c37fb

Please sign in to comment.