diff --git a/src/wp-includes/block-supports/layout.php b/src/wp-includes/block-supports/layout.php
index 22fe6d7b7a51c..98b44079ba747 100644
--- a/src/wp-includes/block-supports/layout.php
+++ b/src/wp-includes/block-supports/layout.php
@@ -312,6 +312,7 @@ function wp_get_layout_style( $selector, $layout, $has_block_gap_support = false
* Renders the layout config to the block wrapper.
*
* @since 5.8.0
+ * @since 6.3.0 Adds compound class to layout wrapper for global spacing styles.
* @access private
*
* @param string $block_content Rendered block content.
@@ -474,6 +475,10 @@ function wp_render_layout_support_flag( $block_content, $block ) {
}
}
+ // Add combined layout and block classname for global styles to hook onto.
+ $block_name = explode( '/', $block['blockName'] );
+ $class_names[] = 'wp-block-' . end( $block_name ) . '-' . $layout_classname;
+
$content_with_outer_classnames = '';
if ( ! empty( $outer_class_names ) ) {
diff --git a/src/wp-includes/class-wp-theme-json.php b/src/wp-includes/class-wp-theme-json.php
index 8a44afbb35ac2..14c0bc73f42a5 100644
--- a/src/wp-includes/class-wp-theme-json.php
+++ b/src/wp-includes/class-wp-theme-json.php
@@ -1221,6 +1221,7 @@ protected function get_block_classes( $style_nodes ) {
* Gets the CSS layout rules for a particular block from theme.json layout definitions.
*
* @since 6.1.0
+ * @since 6.3.0 Reduced specificity for layout margin rules.
*
* @param array $block_metadata Metadata about the block to get styles for.
* @return string Layout styles for the block.
@@ -1317,7 +1318,7 @@ protected function get_layout_styles( $block_metadata ) {
$spacing_rule['selector']
);
} else {
- $format = static::ROOT_BLOCK_SELECTOR === $selector ? '%s .%s%s' : '%s.%s%s';
+ $format = static::ROOT_BLOCK_SELECTOR === $selector ? ':where(%s .%s) %s' : '%s-%s%s';
$layout_selector = sprintf(
$format,
$selector,
@@ -2532,8 +2533,9 @@ public function get_root_layout_rules( $selector, $block_metadata ) {
$has_block_gap_support = _wp_array_get( $this->theme_json, array( 'settings', 'spacing', 'blockGap' ) ) !== null;
if ( $has_block_gap_support ) {
$block_gap_value = static::get_property_value( $this->theme_json, array( 'styles', 'spacing', 'blockGap' ) );
- $css .= '.wp-site-blocks > * { margin-block-start: 0; margin-block-end: 0; }';
- $css .= ".wp-site-blocks > * + * { margin-block-start: $block_gap_value; }";
+ $css .= ":where(.wp-site-blocks) > * { margin-block-start: $block_gap_value; margin-block-end: 0; }";
+ $css .= ':where(.wp-site-blocks) > :first-child:first-child { margin-block-start: 0; }';
+ $css .= ':where(.wp-site-blocks) > :last-child:last-child { margin-block-end: 0; }';
// For backwards compatibility, ensure the legacy block gap CSS variable is still available.
$css .= "$selector { --wp--style--block-gap: $block_gap_value; }";
diff --git a/src/wp-includes/theme.json b/src/wp-includes/theme.json
index af447990608a3..581bdb0b32406 100644
--- a/src/wp-includes/theme.json
+++ b/src/wp-includes/theme.json
@@ -219,14 +219,19 @@
],
"spacingStyles": [
{
- "selector": " > *",
+ "selector": " > :first-child:first-child",
+ "rules": {
+ "margin-block-start": "0"
+ }
+ },
+ {
+ "selector": " > :last-child:last-child",
"rules": {
- "margin-block-start": "0",
"margin-block-end": "0"
}
},
{
- "selector": " > * + *",
+ "selector": " > *",
"rules": {
"margin-block-start": null,
"margin-block-end": "0"
@@ -279,14 +284,19 @@
],
"spacingStyles": [
{
- "selector": " > *",
+ "selector": " > :first-child:first-child",
+ "rules": {
+ "margin-block-start": "0"
+ }
+ },
+ {
+ "selector": " > :last-child:last-child",
"rules": {
- "margin-block-start": "0",
"margin-block-end": "0"
}
},
{
- "selector": " > * + *",
+ "selector": " > *",
"rules": {
"margin-block-start": null,
"margin-block-end": "0"
diff --git a/tests/phpunit/data/blocks/fixtures/core__column.server.html b/tests/phpunit/data/blocks/fixtures/core__column.server.html
index a3624daaf02cf..d0b6ab4016d91 100644
--- a/tests/phpunit/data/blocks/fixtures/core__column.server.html
+++ b/tests/phpunit/data/blocks/fixtures/core__column.server.html
@@ -1,5 +1,5 @@
-
+
Column One, Paragraph One
diff --git a/tests/phpunit/data/blocks/fixtures/core__columns.server.html b/tests/phpunit/data/blocks/fixtures/core__columns.server.html
index 1c144512d1238..e35ab2763e833 100644
--- a/tests/phpunit/data/blocks/fixtures/core__columns.server.html
+++ b/tests/phpunit/data/blocks/fixtures/core__columns.server.html
@@ -1,7 +1,7 @@
-
+
-
+
Column One, Paragraph One
@@ -11,7 +11,7 @@
-
+
Column Two, Paragraph One
diff --git a/tests/phpunit/data/blocks/fixtures/core__columns__deprecated.server.html b/tests/phpunit/data/blocks/fixtures/core__columns__deprecated.server.html
index 9d213ddcdf34e..c61aabf6822a1 100644
--- a/tests/phpunit/data/blocks/fixtures/core__columns__deprecated.server.html
+++ b/tests/phpunit/data/blocks/fixtures/core__columns__deprecated.server.html
@@ -1,5 +1,5 @@
-
+
Column One, Paragraph One
diff --git a/tests/phpunit/data/blocks/fixtures/core__gallery-with-caption.server.html b/tests/phpunit/data/blocks/fixtures/core__gallery-with-caption.server.html
index 18e3f1d8c87bc..49912d63c46c0 100644
--- a/tests/phpunit/data/blocks/fixtures/core__gallery-with-caption.server.html
+++ b/tests/phpunit/data/blocks/fixtures/core__gallery-with-caption.server.html
@@ -1,6 +1,6 @@
diff --git a/tests/phpunit/data/blocks/fixtures/core__gallery.server.html b/tests/phpunit/data/blocks/fixtures/core__gallery.server.html
index fdea3c8ceea09..051cc297b4f25 100644
--- a/tests/phpunit/data/blocks/fixtures/core__gallery.server.html
+++ b/tests/phpunit/data/blocks/fixtures/core__gallery.server.html
@@ -1,6 +1,6 @@
diff --git a/tests/phpunit/data/blocks/fixtures/core__gallery__columns.server.html b/tests/phpunit/data/blocks/fixtures/core__gallery__columns.server.html
index 33bf96793e158..024adf2115e3b 100644
--- a/tests/phpunit/data/blocks/fixtures/core__gallery__columns.server.html
+++ b/tests/phpunit/data/blocks/fixtures/core__gallery__columns.server.html
@@ -1,5 +1,5 @@
-
+
+
diff --git a/tests/phpunit/data/blocks/fixtures/core__gallery__deprecated-2.server.html b/tests/phpunit/data/blocks/fixtures/core__gallery__deprecated-2.server.html
index 4f47253ffb18f..399594ce5943e 100644
--- a/tests/phpunit/data/blocks/fixtures/core__gallery__deprecated-2.server.html
+++ b/tests/phpunit/data/blocks/fixtures/core__gallery__deprecated-2.server.html
@@ -1,5 +1,5 @@
-
+
-
diff --git a/tests/phpunit/data/blocks/fixtures/core__gallery__deprecated-3.server.html b/tests/phpunit/data/blocks/fixtures/core__gallery__deprecated-3.server.html
index 9c58c810349eb..e017c1a0c8c03 100644
--- a/tests/phpunit/data/blocks/fixtures/core__gallery__deprecated-3.server.html
+++ b/tests/phpunit/data/blocks/fixtures/core__gallery__deprecated-3.server.html
@@ -1,5 +1,5 @@
-
+
-
diff --git a/tests/phpunit/data/blocks/fixtures/core__gallery__deprecated-4.server.html b/tests/phpunit/data/blocks/fixtures/core__gallery__deprecated-4.server.html
index 355dc4bdf485a..b835e5f1ab6a8 100644
--- a/tests/phpunit/data/blocks/fixtures/core__gallery__deprecated-4.server.html
+++ b/tests/phpunit/data/blocks/fixtures/core__gallery__deprecated-4.server.html
@@ -1,5 +1,5 @@
-
+
-
diff --git a/tests/phpunit/data/blocks/fixtures/core__gallery__deprecated-5.server.html b/tests/phpunit/data/blocks/fixtures/core__gallery__deprecated-5.server.html
index 57c42cc3bd644..f69cf83abc9cf 100644
--- a/tests/phpunit/data/blocks/fixtures/core__gallery__deprecated-5.server.html
+++ b/tests/phpunit/data/blocks/fixtures/core__gallery__deprecated-5.server.html
@@ -1,5 +1,5 @@
-
+
-
diff --git a/tests/phpunit/data/blocks/fixtures/core__gallery__deprecated-6.server.html b/tests/phpunit/data/blocks/fixtures/core__gallery__deprecated-6.server.html
index 9175cfa56116d..7952cd8c488e3 100644
--- a/tests/phpunit/data/blocks/fixtures/core__gallery__deprecated-6.server.html
+++ b/tests/phpunit/data/blocks/fixtures/core__gallery__deprecated-6.server.html
@@ -1,5 +1,5 @@
-
+
-
diff --git a/tests/phpunit/data/blocks/fixtures/core__gallery__deprecated-7.server.html b/tests/phpunit/data/blocks/fixtures/core__gallery__deprecated-7.server.html
index d3fa62fdf592e..69df4fd1bc9f4 100644
--- a/tests/phpunit/data/blocks/fixtures/core__gallery__deprecated-7.server.html
+++ b/tests/phpunit/data/blocks/fixtures/core__gallery__deprecated-7.server.html
@@ -1,12 +1,12 @@
-
+
-
+
diff --git a/tests/phpunit/tests/block-supports/layout.php b/tests/phpunit/tests/block-supports/layout.php
index 73acce8bc7194..df0abf9b49922 100644
--- a/tests/phpunit/tests/block-supports/layout.php
+++ b/tests/phpunit/tests/block-supports/layout.php
@@ -170,6 +170,7 @@ public function test_outer_container_not_restored_for_aligned_image_block_with_t
/**
* @ticket 57584
+ * @ticket 58548
*
* @dataProvider data_layout_support_flag_renders_classnames_on_wrapper
*
@@ -207,7 +208,7 @@ public function data_layout_support_flag_renders_classnames_on_wrapper() {
),
),
),
- 'expected_output' => '',
+ 'expected_output' => '',
),
'single wrapper block layout with constrained type' => array(
'args' => array(
@@ -226,7 +227,7 @@ public function data_layout_support_flag_renders_classnames_on_wrapper() {
),
),
),
- 'expected_output' => '',
+ 'expected_output' => '',
),
'multiple wrapper block layout with flow type' => array(
'args' => array(
@@ -247,7 +248,7 @@ public function data_layout_support_flag_renders_classnames_on_wrapper() {
),
),
),
- 'expected_output' => '',
+ 'expected_output' => '',
),
);
}
diff --git a/tests/phpunit/tests/media.php b/tests/phpunit/tests/media.php
index 9ea0cc53b087b..3c42f01290abc 100644
--- a/tests/phpunit/tests/media.php
+++ b/tests/phpunit/tests/media.php
@@ -3827,6 +3827,7 @@ public function data_wp_get_loading_attr_default_before_and_no_loop() {
* image in the loop when using a block theme.
*
* @ticket 56930
+ * @ticket 58548
*
* @covers ::wp_filter_content_tags
* @covers ::wp_get_loading_attr_default
@@ -3863,7 +3864,7 @@ public function test_wp_filter_content_tags_does_not_lazy_load_first_image_in_bl
$_wp_current_template_content = '';
$html = get_the_block_template_html();
- $this->assertSame( '' . $expected_content . '
', $html );
+ $this->assertSame( '' . $expected_content . '
', $html );
}
/**
@@ -3871,6 +3872,7 @@ public function test_wp_filter_content_tags_does_not_lazy_load_first_image_in_bl
* to the featured image when using a block theme.
*
* @ticket 56930
+ * @ticket 58548
*
* @covers ::wp_filter_content_tags
* @covers ::wp_get_loading_attr_default
@@ -3918,7 +3920,7 @@ static function( $attr ) {
$_wp_current_template_content = ' ';
$html = get_the_block_template_html();
- $this->assertSame( '' . $expected_featured_image . '
' . $expected_content . '
', $html );
+ $this->assertSame( '' . $expected_featured_image . '
' . $expected_content . '
', $html );
}
/**
diff --git a/tests/phpunit/tests/theme/wpThemeJson.php b/tests/phpunit/tests/theme/wpThemeJson.php
index 8b54960ccfba8..19212bc513d38 100644
--- a/tests/phpunit/tests/theme/wpThemeJson.php
+++ b/tests/phpunit/tests/theme/wpThemeJson.php
@@ -448,6 +448,7 @@ public function test_get_stylesheet_skips_disabled_protected_properties() {
/**
* @ticket 54336
+ * @ticket 58548
*/
public function test_get_stylesheet_renders_enabled_protected_properties() {
$theme_json = new WP_Theme_JSON(
@@ -466,7 +467,7 @@ public function test_get_stylesheet_renders_enabled_protected_properties() {
)
);
- $expected = 'body { margin: 0; }.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }.wp-site-blocks > * { margin-block-start: 0; margin-block-end: 0; }.wp-site-blocks > * + * { margin-block-start: 1em; }body { --wp--style--block-gap: 1em; }';
+ $expected = 'body { margin: 0; }.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }:where(.wp-site-blocks) > * { margin-block-start: 1em; margin-block-end: 0; }:where(.wp-site-blocks) > :first-child:first-child { margin-block-start: 0; }:where(.wp-site-blocks) > :last-child:last-child { margin-block-end: 0; }body { --wp--style--block-gap: 1em; }';
$this->assertSame( $expected, $theme_json->get_stylesheet() );
$this->assertSame( $expected, $theme_json->get_stylesheet( array( 'styles' ) ) );
}
@@ -3299,6 +3300,7 @@ public function test_get_property_value_self() {
* @dataProvider data_get_layout_definitions
*
* @ticket 56467
+ * @ticket 58548
*
* @param array $layout_definitions Layout definitions as stored in core theme.json.
*/
@@ -3325,7 +3327,7 @@ public function test_get_stylesheet_generates_layout_styles( $layout_definitions
// Results also include root site blocks styles.
$this->assertSame(
- 'body { margin: 0; }.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }.wp-site-blocks > * { margin-block-start: 0; margin-block-end: 0; }.wp-site-blocks > * + * { margin-block-start: 1em; }body { --wp--style--block-gap: 1em; }body .is-layout-flow > *{margin-block-start: 0;margin-block-end: 0;}body .is-layout-flow > * + *{margin-block-start: 1em;margin-block-end: 0;}body .is-layout-flex{gap: 1em;}body .is-layout-flow > .alignleft{float: left;margin-inline-start: 0;margin-inline-end: 2em;}body .is-layout-flow > .alignright{float: right;margin-inline-start: 2em;margin-inline-end: 0;}body .is-layout-flow > .aligncenter{margin-left: auto !important;margin-right: auto !important;}body .is-layout-flex{display: flex;}body .is-layout-flex{flex-wrap: wrap;align-items: center;}',
+ 'body { margin: 0; }.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }:where(.wp-site-blocks) > * { margin-block-start: 1em; margin-block-end: 0; }:where(.wp-site-blocks) > :first-child:first-child { margin-block-start: 0; }:where(.wp-site-blocks) > :last-child:last-child { margin-block-end: 0; }body { --wp--style--block-gap: 1em; }:where(body .is-layout-flow) > *{margin-block-start: 0;margin-block-end: 0;}:where(body .is-layout-flow) > * + *{margin-block-start: 1em;margin-block-end: 0;}:where(body .is-layout-flex) {gap: 1em;}body .is-layout-flow > .alignleft{float: left;margin-inline-start: 0;margin-inline-end: 2em;}body .is-layout-flow > .alignright{float: right;margin-inline-start: 2em;margin-inline-end: 0;}body .is-layout-flow > .aligncenter{margin-left: auto !important;margin-right: auto !important;}body .is-layout-flex{display: flex;}body .is-layout-flex{flex-wrap: wrap;align-items: center;}',
$theme_json->get_stylesheet( array( 'styles' ) )
);
}
@@ -3334,6 +3336,7 @@ public function test_get_stylesheet_generates_layout_styles( $layout_definitions
* @dataProvider data_get_layout_definitions
*
* @ticket 56467
+ * @ticket 58548
*
* @param array $layout_definitions Layout definitions as stored in core theme.json.
*/
@@ -3360,7 +3363,7 @@ public function test_get_stylesheet_generates_layout_styles_with_spacing_presets
// Results also include root site blocks styles.
$this->assertSame(
- 'body { margin: 0; }.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }.wp-site-blocks > * { margin-block-start: 0; margin-block-end: 0; }.wp-site-blocks > * + * { margin-block-start: var(--wp--preset--spacing--60); }body { --wp--style--block-gap: var(--wp--preset--spacing--60); }body .is-layout-flow > *{margin-block-start: 0;margin-block-end: 0;}body .is-layout-flow > * + *{margin-block-start: var(--wp--preset--spacing--60);margin-block-end: 0;}body .is-layout-flex{gap: var(--wp--preset--spacing--60);}body .is-layout-flow > .alignleft{float: left;margin-inline-start: 0;margin-inline-end: 2em;}body .is-layout-flow > .alignright{float: right;margin-inline-start: 2em;margin-inline-end: 0;}body .is-layout-flow > .aligncenter{margin-left: auto !important;margin-right: auto !important;}body .is-layout-flex{display: flex;}body .is-layout-flex{flex-wrap: wrap;align-items: center;}',
+ 'body { margin: 0; }.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }:where(.wp-site-blocks) > * { margin-block-start: var(--wp--preset--spacing--60); margin-block-end: 0; }:where(.wp-site-blocks) > :first-child:first-child { margin-block-start: 0; }:where(.wp-site-blocks) > :last-child:last-child { margin-block-end: 0; }body { --wp--style--block-gap: var(--wp--preset--spacing--60); }:where(body .is-layout-flow) > *{margin-block-start: 0;margin-block-end: 0;}:where(body .is-layout-flow) > * + *{margin-block-start: var(--wp--preset--spacing--60);margin-block-end: 0;}:where(body .is-layout-flex) {gap: var(--wp--preset--spacing--60);}body .is-layout-flow > .alignleft{float: left;margin-inline-start: 0;margin-inline-end: 2em;}body .is-layout-flow > .alignright{float: right;margin-inline-start: 2em;margin-inline-end: 0;}body .is-layout-flow > .aligncenter{margin-left: auto !important;margin-right: auto !important;}body .is-layout-flex{display: flex;}body .is-layout-flex{flex-wrap: wrap;align-items: center;}',
$theme_json->get_stylesheet( array( 'styles' ) )
);
}
@@ -3516,7 +3519,7 @@ public function test_get_stylesheet_generates_valid_block_gap_values_and_skips_n
);
$this->assertSame(
- 'body { margin: 0; }.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }.wp-site-blocks > * { margin-block-start: 0; margin-block-end: 0; }.wp-site-blocks > * + * { margin-block-start: 1rem; }body { --wp--style--block-gap: 1rem; }body .is-layout-flow > *{margin-block-start: 0;margin-block-end: 0;}body .is-layout-flow > * + *{margin-block-start: 1rem;margin-block-end: 0;}body .is-layout-flex{gap: 1rem;}body .is-layout-flow > .alignleft{float: left;margin-inline-start: 0;margin-inline-end: 2em;}body .is-layout-flow > .alignright{float: right;margin-inline-start: 2em;margin-inline-end: 0;}body .is-layout-flow > .aligncenter{margin-left: auto !important;margin-right: auto !important;}body .is-layout-flex{display: flex;}body .is-layout-flex{flex-wrap: wrap;align-items: center;}.wp-block-post-content{color: gray;}.wp-block-social-links.is-layout-flow > *{margin-block-start: 0;margin-block-end: 0;}.wp-block-social-links.is-layout-flow > * + *{margin-block-start: 0;margin-block-end: 0;}.wp-block-social-links.is-layout-flex{gap: 0;}.wp-block-buttons.is-layout-flow > *{margin-block-start: 0;margin-block-end: 0;}.wp-block-buttons.is-layout-flow > * + *{margin-block-start: 0;margin-block-end: 0;}.wp-block-buttons.is-layout-flex{gap: 0;}',
+ 'body { margin: 0; }.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }:where(.wp-site-blocks) > * { margin-block-start: 1rem; margin-block-end: 0; }:where(.wp-site-blocks) > :first-child:first-child { margin-block-start: 0; }:where(.wp-site-blocks) > :last-child:last-child { margin-block-end: 0; }body { --wp--style--block-gap: 1rem; }:where(body .is-layout-flow) > *{margin-block-start: 0;margin-block-end: 0;}:where(body .is-layout-flow) > * + *{margin-block-start: 1rem;margin-block-end: 0;}:where(body .is-layout-flex) {gap: 1rem;}body .is-layout-flow > .alignleft{float: left;margin-inline-start: 0;margin-inline-end: 2em;}body .is-layout-flow > .alignright{float: right;margin-inline-start: 2em;margin-inline-end: 0;}body .is-layout-flow > .aligncenter{margin-left: auto !important;margin-right: auto !important;}body .is-layout-flex{display: flex;}body .is-layout-flex{flex-wrap: wrap;align-items: center;}.wp-block-post-content{color: gray;}.wp-block-social-links-is-layout-flow > *{margin-block-start: 0;margin-block-end: 0;}.wp-block-social-links-is-layout-flow > * + *{margin-block-start: 0;margin-block-end: 0;}.wp-block-social-links-is-layout-flex{gap: 0;}.wp-block-buttons-is-layout-flow > *{margin-block-start: 0;margin-block-end: 0;}.wp-block-buttons-is-layout-flow > * + *{margin-block-start: 0;margin-block-end: 0;}.wp-block-buttons-is-layout-flex{gap: 0;}',
$theme_json->get_stylesheet()
);
}
@@ -3958,6 +3961,7 @@ public function data_get_styles_for_block_with_style_variations() {
/**
* @ticket 56611
+ * @ticket 58548
*/
public function test_get_styles_with_appearance_tools() {
$theme_json = new WP_Theme_JSON(
@@ -3974,7 +3978,7 @@ public function test_get_styles_with_appearance_tools() {
'selector' => 'body',
);
- $expected = 'body { margin: 0; }.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }.wp-site-blocks > * { margin-block-start: 0; margin-block-end: 0; }.wp-site-blocks > * + * { margin-block-start: ; }body { --wp--style--block-gap: ; }';
+ $expected = 'body { margin: 0; }.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }:where(.wp-site-blocks) > * { margin-block-start: ; margin-block-end: 0; }:where(.wp-site-blocks) > :first-child:first-child { margin-block-start: 0; }:where(.wp-site-blocks) > :last-child:last-child { margin-block-end: 0; }body { --wp--style--block-gap: ; }';
$root_rules = $theme_json->get_root_layout_rules( WP_Theme_JSON::ROOT_BLOCK_SELECTOR, $metadata );
$this->assertSame( $expected, $root_rules );
}