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

Fix the display of checkboxes when border-box box sizing is applied globally #1861

Merged
merged 2 commits into from
Jul 16, 2020

Conversation

36degrees
Copy link
Contributor

If a user applies a global box-sizing reset, the checkmarks shrink towards the top left corner of the box.

The ::before pseudo-element already uses box-sizing: border-box, so update the ::after pseudo element to use border-box sizing model in order to be consistent. As the box-sizing model is now set explicitly, it should display correctly whether the reset is applied or not.

Increase the width and height of the pseudo elements to include the border widths to accomodate the width of the border (adding an additional 5px to the width and height of normal-sized checkboxes, and 3px to smaller ones).

Switch out the use of $govuk-border-width for a hardcoded 5px width for the check marks, as we don't currently factor this in when positioning the check mark, which means if you change the border width setting the checkbox will no longer be centered (I also just don't think it makes sense to tie the width of the check marks to the border width?)

Fixes #1849

Before

localhost_3000_examples_form-controls-states (4)

After

localhost_3000_examples_form-controls-states (2)

If a user applies a global box-sizing reset [1], the checkmarks shrink towards the top left corner of the box.

The ::before pseudo-element already uses `box-sizing: border-box`, so update the `::after` pseudo element to use border-box sizing model in order to be consistent. As the box-sizing model is now set explicitly, it should display correctly whether the reset is applied or not.

Increase the width and height of the pseudo elements to include the border widths to accomodate the width of the border (adding an additional 5px to the width and height of normal-sized checkboxes, and 3px to smaller ones).

Switch out the use of `$govuk-border-width` for a hardcoded 5px width for the check marks, as we don't currently factor this in when positioning the check mark, which means if you change the border width setting the checkbox will no longer be centered (I also just don't think it makes sense to tie the width of the check marks to the border width?)

[1]: https://css-tricks.com/inheriting-box-sizing-probably-slightly-better-best-practice/
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-review-pr-1861 July 15, 2020 09:20 Inactive
@36degrees 36degrees changed the title Fix checkbox if border-box sizing applied globally Fix the display of checkboxes where border-box box sizing is applied globally Jul 15, 2020
@36degrees 36degrees changed the title Fix the display of checkboxes where border-box box sizing is applied globally Fix the display of checkboxes when border-box box sizing is applied globally Jul 15, 2020
@36degrees 36degrees merged commit f57d338 into master Jul 16, 2020
@36degrees 36degrees deleted the box-sizing-checkboxes branch July 16, 2020 15:27
@vanitabarrett vanitabarrett mentioned this pull request Jul 29, 2020
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.

Checkbox checkmarks are resized if you set box-sizing: border-box
3 participants