diff --git a/lib/block-supports/layout.php b/lib/block-supports/layout.php index ddbd1917c30547..112f9bc978893a 100644 --- a/lib/block-supports/layout.php +++ b/lib/block-supports/layout.php @@ -45,24 +45,26 @@ function gutenberg_get_layout_definitions() { ), ), ), + // First/last child rules need to be after `> *` rule to take + // precedence when they have the same specificity. 'spacingStyles' => array( array( - 'selector' => ' > :first-child', + 'selector' => ' > *', 'rules' => array( - 'margin-block-start' => '0', + 'margin-block-start' => null, + 'margin-block-end' => '0', ), ), array( - 'selector' => ' > :last-child', + 'selector' => ' > :first-child', 'rules' => array( - 'margin-block-end' => '0', + 'margin-block-start' => '0', ), ), array( - 'selector' => ' > *', + 'selector' => ' > :last-child', 'rules' => array( - 'margin-block-start' => null, - 'margin-block-end' => '0', + 'margin-block-end' => '0', ), ), ), @@ -110,24 +112,26 @@ function gutenberg_get_layout_definitions() { ), ), ), + // First/last child rules need to be after `> *` rule to take + // precedence when they have the same specificity. 'spacingStyles' => array( array( - 'selector' => ' > :first-child', + 'selector' => ' > *', 'rules' => array( - 'margin-block-start' => '0', + 'margin-block-start' => null, + 'margin-block-end' => '0', ), ), array( - 'selector' => ' > :last-child', + 'selector' => ' > :first-child', 'rules' => array( - 'margin-block-end' => '0', + 'margin-block-start' => '0', ), ), array( - 'selector' => ' > *', + 'selector' => ' > :last-child', 'rules' => array( - 'margin-block-start' => null, - 'margin-block-end' => '0', + 'margin-block-end' => '0', ), ), ),