Skip to content
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

Fix center aligned images styles #39422

Merged
merged 2 commits into from
Mar 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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; }";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the the two selectors above and added the > there to match the editor. For me that's the right thing to do, it was just something that has been missed originally. We don't intended to define styles for any grand children here, only direct children. (Technically it's not related to this PR but I thought I'd just fix it here)

$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