Skip to content
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

[SPIKE] Tudor crown Safari position tweaks #4423

Closed
wants to merge 12 commits into from

Conversation

colinrotherham
Copy link
Contributor

@colinrotherham colinrotherham commented Nov 3, 2023

Spike for #4297 to fix vertical alignment (Header product name) in Safari #4297 (review)

This PR aligns Chrome and Safari again

Original GOV.UK text

Branch main renders the GOV.UK text and product name 1px too low in Firefox
https://govuk-frontend-review.herokuapp.com/components/header/full-width-with-navigation/preview

Using DPI @1x

Original 1x

Using DPI @2x

Note: We see Safari and Chrome baseline differences using @2x versus @1x

Original 2x

GOV.UK text as SVG

PR #4297 renders the product name 1px too high in Chrome and Safari:
https://govuk-frontend-pr-4297.herokuapp.com/components/header/full-width-with-navigation/preview

Using DPI @1x

Before 1x

Using DPI @2x

Note: We see Safari and Chrome baseline differences using @2x versus @1x but the SVG text is unaffected

Before 2x

GOV.UK text as SVG with position tweaks

PR #4423 (this spike) is correctly aligned:
https://govuk-frontend-pr-4423.herokuapp.com/components/header/full-width-with-navigation/preview

After

There's also a workaround included for Firefox where the text baseline is calculated 1px lower (or 0.5px at @2x DPI) than other browsers, breaking alignment with the product name. This could be "fixed" in Firefox with:

  // Maintain space below logo when wrapped
  margin-top: $product-name-offset;
+ @-moz-document url-prefix() {
+   margin-top: $product-name-offset - 0.5px;
+ }

Firefox also appeared to have issues with some HiDPI resolutions where the top and bottom parts of the Crown (and the GOV.UK text) could subtly move apart as they round to pixel values but this was fixed in fe6f75b

Related Firefox issues regarding SVG rendering accuracy:

@colinrotherham colinrotherham changed the base branch from main to new-crown-v5 November 3, 2023 14:56
@colinrotherham colinrotherham marked this pull request as draft November 3, 2023 14:56
Copy link

github-actions bot commented Nov 3, 2023

📋 Stats

File sizes

File Size
dist/govuk-frontend-5.0.0-beta.1.min.css 114 KiB
dist/govuk-frontend-5.0.0-beta.1.min.js 37.93 KiB
packages/govuk-frontend/dist/govuk/all.bundle.js 77.02 KiB
packages/govuk-frontend/dist/govuk/all.bundle.mjs 72.35 KiB
packages/govuk-frontend/dist/govuk/all.mjs 3.8 KiB
packages/govuk-frontend/dist/govuk/govuk-frontend-component.mjs 359 B
packages/govuk-frontend/dist/govuk/govuk-frontend.min.css 113.64 KiB
packages/govuk-frontend/dist/govuk/govuk-frontend.min.js 37.94 KiB
packages/govuk-frontend/dist/govuk/i18n.mjs 5.3 KiB

Modules

File Size
all.mjs 68.67 KiB
components/accordion/accordion.mjs 21.37 KiB
components/button/button.mjs 4.48 KiB
components/character-count/character-count.mjs 20.78 KiB
components/checkboxes/checkboxes.mjs 5.61 KiB
components/error-summary/error-summary.mjs 5.79 KiB
components/exit-this-page/exit-this-page.mjs 15.79 KiB
components/header/header.mjs 3.68 KiB
components/notification-banner/notification-banner.mjs 4.32 KiB
components/radios/radios.mjs 4.6 KiB
components/skip-link/skip-link.mjs 3.6 KiB
components/tabs/tabs.mjs 9.33 KiB

View stats and visualisations on the review app


Action run for 058b443

@include govuk-typography-responsive($size: 24, $override-line-height: 1);
@include govuk-typography-weight-regular;
display: inline-table;
vertical-align: top;
Copy link
Contributor Author

@colinrotherham colinrotherham Nov 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we'd keep vertical-align: baseline; but it appears 1px lower in Chrome vs. Safari or Firefox

But for now, it's more reliable to use vertical-align: top with a margin

In future we could tweak font-size: 30px (or reset to font-size: 0) to try and solve the variation:

// Font size needs to be set on the link so that the box sizing is correct
// in Firefox
@include govuk-typography-weight-bold;
display: inline-block;
margin-right: govuk-spacing(2);
font-size: 30px; // We don't have a mixin that produces 30px font size
line-height: 1;

@@ -98,7 +113,7 @@
font-size: 30px; // We don't have a mixin that produces 30px font size
line-height: 1;

@include govuk-media-query($from: tablet) {
@include govuk-media-query($from: desktop) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@owenatgov Having an parent link with display: inline didn't help child alignment, but think it's a bug from #2549 where display: inline was added at tablet size but the product name didn't wrap until desktop

@querkmachine
Copy link
Member

This seems to have done the job in desktop Safari, though—just to add some more pixelpushing fun to the equation—it now appears to be slightly misaligned in iOS Safari where it wasn't before. Only by a pixel, so might need to click through to the full size image.

Composite screenshot of three Safari on iPad screens, showing the header as it appears on the main branch, in PR 4297 and PR 4423. The two PRs use a different crown. The logo in PR 4423 is slightly shifted up compared to the other two.

Outside of that, I think this could use some code comments explaining what's going on. Why is padding and alignment being changed between mobile and tablet? Why does it become inline on desktop? Why is a Firefox 'hack' needed and why does a fractional pixel value fix it?

More generally, and not specific to this PR, was the product name always positioned like this regardless of viewport size? I'm not sure it was like this in v4?

Screenshot of the GOV.UK header with a product name, which is rendering below the logo across all screen sizes.

@colinrotherham
Copy link
Contributor Author

@querkmachine Ah that's fair, I only checked tablet and desktop

Hopefully enough of a spike to demonstrate what's possible, or that the SVG points needs snapping to pixels otherwise Firefox is going to go ahead and do it anyway 😣

See #4423 (comment) for "Why does it become inline on desktop?"

Do you want me to hand back over to you or shall I answer the other questions?

@querkmachine
Copy link
Member

@colinrotherham I've updated #4297 with a tweaked SVG that snaps some of those errant .005px coordinates to their full number.

At a glance, the lockup appears to be rendering in the right position on Firefox and iOS Safari and 1px lower than the product name in Chrome and macOS Safari. Can you corroborate that that's what you see too?

@colinrotherham
Copy link
Contributor Author

Sorry for the delay @querkmachine

Yeah, for the GOV.UK part it's exactly as you said, 1px too low in Chrome and macOS Safari now. Taking just the Product Name text though, it's perfectly v-aligned in Chrome, Firefox and Safari

I think we should go back to it just being Firefox misaligned and apply the CSS hack

- Add new GOV.UK logo lockup with Tudor crown and integrated GOV.UK text
- Removes HTML and classes that used to wrap the logo group as these are no longer needed
- Adjust the vertical offset of the logo to align with productName text
- Tweak attributes to ensure logo is available to assistive technologies
@colinrotherham
Copy link
Contributor Author

@querkmachine Mind taking another look?

The new SVGs have definitely helped as has using a single compound path

querkmachine and others added 4 commits November 14, 2023 17:45
When switching between services with different crowns we should exactly vertically align the GOV.UK text
We use the logotype SVG for bold “GOV.UK” instead
Fixed by adding `vertical-align: top` but uses margin to restore the gap underneath the logo when long product names wrap below
Firefox appears to calculate the baseline differently

This fix uses an offset of `- 0.5px` to fix both `@1x` and `@2x` displays
At tablet sizes and up, the `govuk-header__logo` element rendered at `30.5px` height (or `30.25px` on high DPI displays) due to line-height of empty space previously occupied by GOV.UK text
@colinrotherham colinrotherham changed the base branch from new-crown-v5 to main November 16, 2023 14:21
The link was given `display: inline` at tablet sizes but the product name doesn’t wrap until desktop: #2549
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-4423 November 16, 2023 14:22 Inactive
@querkmachine
Copy link
Member

I've now merged the code changes from this spike into the branches for v5.0 (#4449) and v5.x (#4297). If everything in those branches is looking good, this spike can be shut down.

Thanks for spending the time to look at this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants