Skip to content

Commit

Permalink
Prevent details and summary margins collapsing
Browse files Browse the repository at this point in the history
Now that we’re no longer using `display: inline-block` [^1], the the 5px bottom margin on the summary and the 30px bottom margin on the details now collapse when the <details> is closed *except* in Chrome which has been updated to use `content-visibility` [2].

Preserve the existing margin on the component and make the behaviour across browsers consistent by establishing a new block formatting context using `display: flow-root`, preventing the margins from collapsing.

Safari < 13 does not support `display: flow-root` and so the margins will collapse, which means these older versions of Safari will have 5px less margin than when we were still using `display: inline-block`.

[^1]: ‘margins of inline-block boxes do not collapse (not even with their in-flow children)’ – https://www.w3.org/TR/CSS21/box.html#collapsing-margins
[2]: https://issues.chromium.org/issues/40815464
[3]: https://html.spec.whatwg.org/multipage/rendering.html#the-details-and-summary-elements
  • Loading branch information
36degrees committed Jun 18, 2024
1 parent 6d10727 commit 9a75836
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
@include govuk-text-colour;
@include govuk-responsive-margin(6, "bottom");

display: block;
// Prevent bottom margins on summary and details from collapsing in Firefox
// and Safari, matching Chrome's behaviour (https://crbug.com/40815464)
display: flow-root;
}

.govuk-details__summary {
Expand Down

0 comments on commit 9a75836

Please sign in to comment.