From c9d777e7806b41658045cbf83db4d9657660c0bf Mon Sep 17 00:00:00 2001 From: Daniel Richards Date: Wed, 31 Jul 2024 12:34:58 +0800 Subject: [PATCH] Ensure first/last child rules take precedence --- lib/block-supports/layout.php | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/lib/block-supports/layout.php b/lib/block-supports/layout.php index ddbd1917c3054..112f9bc978893 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', ), ), ),