The “em” is a scalable unit. An em is equal to the current font-size
, for instance, if the font-size
of the document is 12px
, 1em
is equal to 12px
. Ems are scalable in nature, so 2em
would equal 24px
, .5em
would equal 6px
, etc.
The size can be calculated from pixels to em using this formula: pixels/12(current font-size
)=em
Check out http://www.w3schools.com/css/css_font.asp
In media queries “rem” as well as “em” don’t refer to the root element (html) but to the browser defaults directly which can only be changed using the browser settings for base font size. This means that even if you specify a font size of 30px on your html element, media queries will still use "user agent's (browser's) initial font-size" as “em” / “rem” based for the media queries unless you also change your default font size in the browser settings.
I will use(for the good of math):
"user agent's initial font-size" = 10px;
So let say you have:
@media (max-width: 59em) {
}
@media (min-width: 60em) {
}
When the browser compute the em
that will be equal to:
@media (max-width: 590px) { // 59 * 10(supposed font-size)
}
@media (min-width: 600px) { // 60 * 10(supposed font-size)
}
Here you have a range of 10px
where the screen could between the 2 media queries.
Probably you would say, I do a little math and solve the problem but to do math in css there is calc
like this:
@media (max-width: calc(60em - 1px);) { // 60 * 10 = 600px - 1px = 599px
}
@media (min-width: 60em) { // 60 * 10 = 600px
}
But unfortunately calc() not working within media queries.
But 1px = 0.1em 1 / 10(supposed font-size)
So you have to do the math a priori:
@media (max-width: calc(59.9em);) { // 60em - 0.1em(1px) = 59.9 * 10 = 599px
}
@media (min-width: 60em) { // 60 * 10 = 600px
}
So the only that you have to do is change the "10" to the "user agent's (browser's) initial font-size" and do the math a priori.
I hope this help you.