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 font-size scaling for text-related CSS properties by using rem instead of fixed px values; deprecate $root-font-size #1169

Merged
merged 8 commits into from Jun 16, 2023

Conversation

mattxwang
Copy link
Member

@mattxwang mattxwang commented Feb 16, 2023

This PR replaces all uses of px in relation to font size (opposed to borders, spacing, etc.) with the equivalent rem value when the body font size is 16px. The intention is to better scale the website when the user changes the font size for <body> (often done for accessibility reasons).

This PR is technically a breaking change, though it's a minor one (see subheading below). I'm putting this up so that we can discuss it as a community.

(technically closes #1088 and fixes #1073, but let's see if we end up merging this)

mechanics

To do this, I systematically went through every px value for all .scss files. Then, I deleted the rem function, the _functions.scss file (that was the only function there), and removed the import from support.scss. A nice side effect of this is that we no longer perform any SASS division.

The only remaining uses of px are for either:

  • border-related properties
  • shadow-related properties
  • sizing for "non-text" elements (ex hr, blockquote decorative spacing)
  • $root-font-size (see below)

The only pixel value change in this PR is the padding-left for blockquote, which I've changed from 15px to 1rem (which is 16px in the "stock" theme).

deprecating $root-font-size

There's a SCSS variable called $root-font-size. It is used in two places:

  1. the rem() function
  2. the .site-title when printing (i.e. a @print style)

The changes I listed above let us ignore the first case. The second case seems like it has the intention of matching the body font size, so I replaced it with 1rem.

We can choose to leave the variable in (in case others use it in custom code - which I'm sure that some do) and leave a deprecation notice, or just remove it now. I'm leaning towards the former, which is less disruptive.

how users would upgrade

This is a breaking change of some sorts, but the change is very straightforward for users:

  1. If they do not change $root-font-size, they need to do nothing; this PR is a no-op.
  2. if they do change $root-font-size
    • they should instead set the font-size of body with the appropriate px value
    • optionally, they can replace all custom code that uses $root-font-size with 1rem (find-and-replace works here)

@mattxwang mattxwang changed the title Use rem instead of px in certain SASS units Use rem instead of px for all text related CSS properties Feb 18, 2023
@mattxwang mattxwang marked this pull request as ready for review February 18, 2023 00:28
@mattxwang mattxwang requested a review from a team March 31, 2023 20:20
@pdmosses pdmosses mentioned this pull request Apr 13, 2023
@mattxwang mattxwang linked an issue Apr 14, 2023 that may be closed by this pull request
@mattxwang
Copy link
Member Author

A quick light ping for @just-the-docs/reviewers; if anybody has capacity to take a look at this change, that would be great! It will finally resolve all warnings on build, and I'll move on to some other requested work - e.g. automatic theme switching.

Copy link

@cking0987 cking0987 left a comment

Choose a reason for hiding this comment

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

This looks great. I double-checked the math on all the new REM values. Removing the functions.scss file cleans things up nicely. The site builds perfectly (no more depreciation warning about division). Just two comments:

  1. It's worth mentioning that you decided to go with the non-breaking option to leave the $root-font-size variable. So I think this PR is no longer a breaking change.
  2. The left padding for blockquotes was changed from 15px to 1rem. This is the only conversion that wasn't exactly equivalent at 16px=1rem. But I don't think it matters— they still look like blockquotes.

@mattxwang
Copy link
Member Author

Thanks for the quick review @cking0987, and sorry to leave you hanging! Great opportunity to cut a new release and address one of our recent headaches.

@mattxwang mattxwang changed the title Use rem instead of px for all text related CSS properties Fix font-size scaling for text-related CSS properties by using rem; deprecate $root-font-size Jun 16, 2023
@mattxwang mattxwang changed the title Fix font-size scaling for text-related CSS properties by using rem; deprecate $root-font-size Fix font-size scaling for text-related CSS properties by using rem instead of fixed px values; deprecate $root-font-size Jun 16, 2023
@mattxwang mattxwang merged commit 4151d46 into main Jun 16, 2023
19 checks passed
@mattxwang mattxwang deleted the remify-units branch June 16, 2023 02:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

Resolve last case of Slash as Division in SASS Deprecation warnings
2 participants