Working in my last project I needed to change the measure of some elements to the 60% to adapt them to mobile browsers.
At the beginning I’ve tried to do it with CSS ‘rem’ units but it didn’t seems to work as expected in Android browser :S (it works great in last ios6, firefox mobile, and chrome and firefox desktop. I’ve stop my tests when it fails in Android browser )
The alternative was do it with ‘pixel’ units in plain CSS, but this is a pain in the ass. You have to calculate all the measures “by hand” and declare again the elements in the media queries. The worst part is if you need to change the percentage after completion… because you have to recalculate all the measures and this make impossible (well possible but large) the test / error…
So, I switch to sass and create a mixin to generate the media queries automatically based on the size of every element:
To use it in my elements:
Note that I put the measure of the element between the parentheses and the properties followed by the variable $px between the braces.
This is the result when you compile the scss file into css:
The problem with this is that every time you use the mixin it creates a new media query entry in your css:
I didn’t found a way to resolve this issue, but it works well in all browsers (I didn’t notice any problem of performance but I prefer a clean code and if you use it a lot it’s going to increase also the weight of your css file. If you know a way to solve this issue don’t hesitate to tell me 🙂 ).
Now I can easily change the measures of all my elements for mobiles or tablets at the same time changing the $responsive_resize variable.