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

Replace ex units with ems for input lengths #2678

Merged
merged 1 commit into from
Jul 1, 2022
Merged

Conversation

querkmachine
Copy link
Member

@querkmachine querkmachine commented Jun 29, 2022

It was recently questioned why we were using ex units (a unit equivalent to the font's x-height) to define the width of inputs. Ultimately, the original reasoning appears to have been lost to time.

This PR replaces the use of ex units with em equivalents for Input lengths.

This makes sense as:

  • em units are based on typeface width, rather than the height
  • em and ex are both based on the font size, both affect the width of the input when the body font size is changed
  • ex units are calculated differently by different browsers — IE 'cheats' and makes ex always equal half of em

Rather than make one-to-one replacements of ex for em, I rounded the em units up to the nearest .25. This prevents an excessive amount of decimal places in the resulting pixel measurements, but does mean that these inputs are up to a few pixels wider than previously.

Input length old ex new em old px new px
2 5.4 2.75 51.217 52.25
3 7.2 3.75 68.283 71.25
4 9.0 4.50 85.350 85.50
5 10.8 5.50 102.417 104.50
10 23.0 11.50 218.117 218.50
20 41.0 20.50 388.817 389.50
30 59.0 29.50 559.517 560.50

@querkmachine querkmachine marked this pull request as draft June 29, 2022 13:28
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-2678 June 29, 2022 13:28 Inactive
@owenatgov owenatgov self-requested a review June 29, 2022 13:29
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-2678 June 29, 2022 13:36 Inactive
@owenatgov owenatgov removed their request for review June 29, 2022 13:36
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-2678 June 29, 2022 14:10 Inactive
@querkmachine querkmachine marked this pull request as ready for review July 1, 2022 08:37
@vanitabarrett
Copy link
Contributor

I'm pretty happy with this, looks good and I don't think the slight difference in width should have a big impact on anyone 👍

@owenatgov - you did the initial review. Do you want to re-review? Also happy for you to look at the failing Percy build and approve it if you'd like. First time I think we're actually doing that!

Copy link
Contributor

@owenatgov owenatgov left a comment

Choose a reason for hiding this comment

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

❌ 🙅🏻 Ⓜ️ 👌🏻

@querkmachine querkmachine merged commit 8456499 into main Jul 1, 2022
@querkmachine querkmachine deleted the replace-ex-with-em branch July 1, 2022 09:41
@querkmachine querkmachine mentioned this pull request Aug 9, 2022
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.

4 participants