-
Notifications
You must be signed in to change notification settings - Fork 324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoid unnecessary spacing-related media queries #2737
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
When the `$govuk-spacing-responsive-scale` map is processed by the `_govuk-responsive-spacing` mixin, a media query is outputted in the CSS for each breakpoint defined in the map. (The ‘null’ breakpoint is a special case and is outputted outside of any media query as the ‘baseline’ spacing.) However, at the lower end of the spacing scale (0-3) there is no difference between the ‘baseline’ spacing and the spacing on tablet and above. With the existing settings, this means that we end up outputting a ‘redundant’ media query targeting the breakpoint which defines spacing that is exactly the same as the baseline spacing. For example: ```css .govuk-\!-margin-1 { margin: 5px !important } @media (min-width:40.0625em) { .govuk-\!-margin-1 { margin: 5px !important } } ``` We can avoid this by simply omitting the tablet breakpoint from the spacing scale where it does not differ from the baseline, and relying on the baseline spacing being applied everywhere: ```css .govuk-\!-margin-1 { margin: 5px !important } ``` As well as affecting the override classes, this also affects any CSS outputted by the `govuk-responsive-margin` or `govuk-responsive-margin` helpers where spacing units 0-3 are passed. In the rest of the Frontend codebase this includes the: - Accordion - Header - Tabs ```diff diff --git a/dist-main/govuk-frontend-4.2.0.min.css b/dist/govuk-frontend-4.2.0.min.css index 0e8c0776..97225cfb 100644 --- a/dist-main/govuk-frontend-4.2.0.min.css +++ b/dist/govuk-frontend-4.2.0.min.css @@ -1204,8 +1204,7 @@ @media (min-width:40.0625em) { .js-enabled .govuk-accordion__section-content { - padding-bottom: 50px; - padding-top: 15px + padding-bottom: 50px } } @@ -4051,12 +4050,6 @@ only screen and (min-resolution:192dpi) { padding-right: 50px } -@media (min-width:40.0625em) { - .govuk-header__logo { - margin-bottom: 10px - } -} - @media (min-width:48.0625em) { .govuk-header__logo { width: 33.33%; @@ -5106,7 +5099,6 @@ only screen and (min-resolution:192dpi) { @media (min-width:40.0625em) { .govuk-tabs { - margin-top: 5px; margin-bottom: 30px } } @@ -5349,15 +5341,7 @@ only screen and (min-resolution:192dpi) { border: 1px solid #b1b4b6; border-top: 0 } -} - -@media (min-width:40.0625em) and (min-width:40.0625em) { - .js-enabled .govuk-tabs__panel { - margin-bottom: 0 - } -} -@media (min-width:40.0625em) { .js-enabled .govuk-tabs__panel>:last-child { margin-bottom: 0 } @@ -6191,202 +6175,82 @@ screen and (forced-colors:active) { margin: 0 !important } ``` (Changes to spacing override classes omitted for brevity) In testing this saves 3,426 bytes (167 gzipped) – 106,896 bytes (13,025 gzipped) compared to 110,322 bytes (13,192 gzipped) for the equivalent ‘dist’ CSS file without these changes applied.
36degrees
added a commit
to alphagov/govuk_publishing_components
that referenced
this pull request
Jul 29, 2022
This is to test the changes in alphagov/govuk-frontend#2737 against the publishing components to see if any visual regressions are introduced.
36degrees
added a commit
to alphagov/govuk_publishing_components
that referenced
this pull request
Jul 29, 2022
This is to test the changes in alphagov/govuk-frontend#2737 against the publishing components to see if any visual regressions are introduced.
I updated GOV.UK Publishing Components to use a pre-release with just these changes rebased onto the v4.2.0 tag (39abfcc) and there were no changes according to their visual regression tests either. |
querkmachine
approved these changes
Aug 1, 2022
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
36degrees
changed the title
Avoid unneccesary spacing-related media queries
Avoid unnecessary spacing-related media queries
Aug 1, 2022
Merged
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When the
$govuk-spacing-responsive-scale
map is processed by the_govuk-responsive-spacing
mixin, a media query is outputted in the CSS for each breakpoint defined in the map.(The ‘null’ breakpoint is a special case and is outputted outside of any media query as the ‘baseline’ spacing.)
However, at the lower end of the spacing scale (0-3) there is no difference between the ‘baseline’ spacing and the spacing on tablet and above.
With the existing settings, this means that we end up outputting a ‘redundant’ media query targeting the breakpoint which defines spacing that is exactly the same as the baseline spacing. For example:
We can avoid this by simply omitting the tablet breakpoint from the spacing scale where it does not differ from the baseline, and relying on the baseline spacing being applied everywhere:
As well as affecting the override classes, this also affects any CSS outputted by the
govuk-responsive-margin
orgovuk-responsive-margin
helpers where spacing units 0-3 are passed.In the rest of the Frontend codebase this includes the:
(Changes to spacing override classes omitted for brevity)
In testing this saves 3,426 bytes (167 gzipped) – 106,896 bytes (13,025 gzipped) compared to 110,322 bytes (13,192 gzipped) for the equivalent ‘dist’ CSS file without these changes applied.