-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[v4] Don’t try to size html to 10px #1590
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,8 @@ | ||
| $default-browser-font-size: 16px; | ||
| $base-font-size: 10px; | ||
| $root-font-size: 16px; | ||
|
|
||
| /// Returns the value in rem for a given pixel value. | ||
| /// @param {Number} $value - The pixel value to be converted. | ||
| /// Returns the value in rem for a given length value. | ||
| /// Note: converting ems only works for elements that have had no font-size changes. | ||
| /// @param {Number} $value - The value (em, rem, or px) to be converted. | ||
| /// @return {Number} The converted value in rem. | ||
|
|
||
| @function rem($value) { | ||
|
|
@@ -13,15 +13,18 @@ $base-font-size: 10px; | |
| } @else if $unit == 'rem' { | ||
| @return $value; | ||
| } @else if $unit == 'px' { | ||
| @return $value / $base-font-size * 1rem; | ||
| // e.g. 16px × 1rem/16px = 1rem | ||
| @return $value * (1rem / $root-font-size); | ||
| } @else if $unit == 'em' { | ||
| @return $unit / 1em * 1rem; | ||
ry5n marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // This is a fudge; it assumes 1em == 1rem | ||
| @return $value / 1em * 1rem; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixing this bug means we'll now have to support it. Since we know nobody is using this (or they'd have submitted an issue), I vote for removing this part completely: - } @else if $unit == 'em' {
- @return $unit / 1em * 1rem;
# and also:
- @error 'Value must be in px, em, or rem.';
+ @error 'Value must be in px, or rem.';
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The thing is we’re supporting this API already, and fixing it is low cost. I’d be all for removing em unit conversion if it wasn’t needed. However, we convert to ems in our own code, so we have to support that. The most we could do is remove converting from em units. That seems like a strangely asymmetric API to me. Is there really any downside to just shipping this bug fix?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point about the asymmetric API, but at the same time we have evidence that a piece of code is not being used. I'm not going to block this PR from being merged because of this detail, but I'd like us to consider how we can try to ship things that are needed, rather than things we might need.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks Kaelig. I see where you’re coming from, and I appreciate it. In general I definitely support not adding (and deleting!) code we don’t use. |
||
| } @else { | ||
| @error 'Value must be in px, em, or rem.'; | ||
| } | ||
| } | ||
|
|
||
| /// Returns the value in pixels for a given rem value. | ||
| /// Returns the value in pixels for a given length value. | ||
| /// Note: converting ems only works for elements that have had no font-size changes. | ||
| /// @param {Number} $value - The rem value to be converted. | ||
| /// @return {Number} The converted value in pixels. | ||
|
|
||
|
|
@@ -33,17 +36,20 @@ $base-font-size: 10px; | |
| } @else if $unit == 'px' { | ||
| @return $value; | ||
| } @else if $unit == 'em' { | ||
| @return ($value / 1em) * $base-font-size; | ||
| // This is a fudge; it assumes 1em == 1rem | ||
| // e.g. 1em × 16px/em = 16px | ||
| @return $value * ($root-font-size / 1em); | ||
| } @else if $unit == 'rem' { | ||
| @return ($value / 1rem) * $base-font-size; | ||
| // e.g. 1rem × 16px/rem = 16px | ||
| @return $value * ($root-font-size / 1rem); | ||
| } @else { | ||
| @error 'Value must be in rem, em, or px.'; | ||
| } | ||
| } | ||
|
|
||
| /// Returns the value in ems for a given pixel value. Note that this | ||
| /// only works for elements that have had no font-size changes. | ||
| /// @param {Number} $value - The pixel value to be converted. | ||
| /// Returns the value in ems for a given length value. | ||
| /// Note: only works for elements that have had no font-size changes. | ||
| /// @param {Number} $value - The value (em, rem, or px) to be converted. | ||
| /// @return {Number} The converted value in ems. | ||
|
|
||
| @function em($value) { | ||
|
|
@@ -54,9 +60,12 @@ $base-font-size: 10px; | |
| } @else if $unit == 'em' { | ||
| @return $value; | ||
| } @else if $unit == 'rem' { | ||
| @return $value / 1rem * 1em * ($base-font-size / $default-browser-font-size); | ||
| // This is a fudge; it assumes 1em == 1rem | ||
| @return $value / 1rem * 1em; | ||
| } @else if $unit == 'px' { | ||
| @return $value / $default-browser-font-size * 1em; | ||
| // This is a fudge; it assumes 1em == 1rem | ||
| // e.g. 14px × 1em/16px = 0.875em | ||
| @return $value * (1em / $root-font-size); | ||
| } @else { | ||
| @error 'Value must be in px, rem, or em.'; | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.