Created
July 13, 2012 18:55
-
-
Save brianblakely/3106678 to your computer and use it in GitHub Desktop.
Simulate vw with rems
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Android stock browser won't let you set font-size smaller than 8px unless you apply this. */ | |
:root { | |
-webkit-text-size-adjust: none; | |
-moz-text-size-adjust: none; | |
-ms-text-size-adjust: none; | |
-o-text-size-adjust: none; | |
text-size-adjust: none; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Place this within a <script> in your <head>, prior to your stylesheet | |
Then use rems instead of px globally - your site will scale 1:1 with viewport width | |
*/ | |
function remCalibrate() { | |
document.documentElement.style.fontSize = window.innerWidth/100 + 'px'; | |
} | |
remCalibrate(); | |
window.addEventListener('resize', remCalibrate, false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Its great, thanks !
however there is few problems with this technique :
it could lead to very small or big fonts when screen size is getting smaller or larger, so we could make some min, max to this function
it doesn't take into account the aspect ratio of the screen, on a lot of laptop, the users have a much wider screen than the window height, so this computation tend to deliver them a greater font, that it should.
I had to adapt it for a one-page size all project and come up with a naive implementation, that patch the size according to 4:3 aspect ratio to compensate and using a [8,24] clipping range.
so its something like :