Skip to content

Commit

Permalink
Navigation: Use gap instead of margin. (#32367)
Browse files Browse the repository at this point in the history
* Use gap instead of margin.

* Unset classic margins.

* Address feedback.
  • Loading branch information
jasmussen committed Sep 2, 2021
1 parent 5b704ad commit b029315
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 20 deletions.
7 changes: 7 additions & 0 deletions packages/block-library/src/navigation/editor.scss
Expand Up @@ -11,6 +11,13 @@
margin-left: 0;
padding-left: 0;
}

// Revert any left/right margins.
// This also makes it work with classic theme auto margins.
.wp-block-navigation-item.wp-block {
margin-left: revert;
margin-right: revert;
}
}

// This element is inline on the frontend but needs to be editable, therefore inline-block, in the editor.
Expand Down
26 changes: 6 additions & 20 deletions packages/block-library/src/navigation/style.scss
Expand Up @@ -208,35 +208,22 @@

/**
* Margins
* @todo: refactor this to use gap.
*/

// Menu items with no background.
.wp-block-page-list,
.wp-block-page-list > .wp-block-navigation-item,
.wp-block-navigation__container > .wp-block-navigation-item {
margin: 0 2em 0 0;

// Margin of right-most margin should be zero, for right aligned or justified items.
&:last-child {
margin-right: 0;
}
.wp-block-navigation .wp-block-page-list,
.wp-block-navigation__container {
gap: 0.5em 2em;
}

// Menu items with background.
// We use :where to keep specificity minimal, yet still scope it to only the navigation block.
// That way if padding is set in theme.json, it still wins.
// https://css-tricks.com/almanac/selectors/w/where/
.wp-block-navigation:where(.has-background) {
.wp-block-page-list,
.wp-block-page-list > .wp-block-navigation-item,
.wp-block-navigation__container > .wp-block-navigation-item {
margin: 0 0.5em 0 0;

// Don't show right margin on the last child.
&:last-child {
margin: 0;
}
.wp-block-navigation .wp-block-page-list,
.wp-block-navigation__container {
gap: 0 0.5em;
}
}

Expand Down Expand Up @@ -357,7 +344,6 @@
align-items: flex-end;

.wp-block-navigation-item {
margin-right: 0;
justify-content: flex-end;
}
}
Expand Down

0 comments on commit b029315

Please sign in to comment.