-
Notifications
You must be signed in to change notification settings - Fork 20
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
Support rem units #1
Comments
Hi, did some math and got the following (sass) result: $mult: strip-unit($font-max - $font-min) / strip-unit($width-max - $width-min);
font-size: calc(#{$font-min - $width-min * $mult} + #{$mult * 100}vw) ; This not only results in a much nicer Example output: font-size: calc(4.8px + 1.6vw)
font-size: calc(.3rem + 1.6vw)
font-size: calc(.3em + 1.6vw) |
Ooh nice one. I'll look at porting this over to js when I get the chance (or would happily welcome a PR). Haven't actually tested this myself yet but definitely looks more flexible w/ cleaner output. That said I don't think it really solves the rem issue. Breakpoints are almost unanimously given in px, and forcing rem for them would be unreasonable. But it should be fairly trivial to detect px + rem deceleration then fetch the base font size and convert the px portion to rem, to feed into this more generalised logic. |
I would have PRed already but I'm a bit short of spare time at the moment. 😓 I'm still investigating on best units for media queries, what the advantages or disadvantages are. As for "unanimously given", I've seen both. For example Bootstrap uses After thinking a bit about it, the So the correct and only possible way would be to convert the fontsizes to whatever units the widths have. |
Not entirely sure what you mean here. Browsers set a default root font size of 16px, and overriding this on the doc root (ie: In any case, when I get a chance I’ll check out and port your new sizing logic, and since that will add basic rem support, I’ll just open a new ticket for mixed units. Again, should be fairly trivial to implement, I’m just strapped for time atm. |
What I mean is, that the relative units in media queries are based on the initial values (set by the browser) no matter what you set an doc root. See spec:
A unit conversion of width values pre runtime seems to be rather impossible for me. So the only way would be adjusting the font size units to what ever the width unit is. |
oh right, didn't realise that. After a bit of digging, it seems rem mq's are useless at best (http://fvsch.com/code/bugs/rem-mediaquery/) and flat out don't work at worst (https://bugs.webkit.org/show_bug.cgi?id=78295). And as you point out, em media queries are based off the parent initial value, which is the browser/root, which = 16px across the board. The user changing zoom level changes this base, which handily also changes the base of rem units. So, a few different use-cases:
I think that covers just about everything. There might be a few edge cases here and there, but generally that logic sounds fairly solid to me. |
Ok, the link above was from 2012 and the bug was fixed at least 2,5 years ago so I don't see there a big problem. E.g. an up to date Chrome doesn't seem to have any problems with rem in mq's. Anyway, as em is relative to the parent and there's no parent of root, rem and em should be absolutely identical in mq's, so the rem units could be simply replaced by em for the sake of possible very old browsers. |
Really? I'm on the latest chrome and the rem mqs in that demo were way off. Also that bug was last updated in late 2014 and is still open. Admittedly I didn't test any further than that, because using rem in mq's is pointless regardless, as it simply equates to em, which has more support. |
Don't trust a test you didn't forged yourself. html {font-size: 20px;}
#red {width: 50rem; background: #F00;}
@media screen and (max-width:50rem) { html{background: #FAA;} } I can't work as we know, the red bar is calculated with a 20px base and the mq with (probably) a 16px base. Set your Chrome base font size to 20px and the test works exactly as the author wants. But as I said, simply |
Will have to check what font-size declared on
html
(if any, default to 16px), then calculate all rem values before mixing them into responsive declaration.Mixing up
px
andrem
units will be a pain (eg:rem
font sizes andpx
media queries).The text was updated successfully, but these errors were encountered: