Remember em? Yeah!!..it has been renamed by CSS3 working group..believe that? You don't, actually, em and rem are siblings, rem being the most modern & advanced one.. I will introduce you with that but lets first start with their neighbour..px(pixel) unit.
px has been around ever since I started working and is most consistent and reliable. Most of the UI developers use it but if you are a usability concerned developer, you will not use it. Reason being, Internet explorer users can not use the browser default capabilities are increasing/decreasing the font size.
To over come the text-resizing issue in IE, em has been used for a long time. But the problem with the em based font-size is that the font-size is compound. See the example below. Using 62.5% for body so that I don't need to calculate the em value every time I need to use the unit.
body{font-size:62.5%}
p{font-size:1em} /*10px*/
h1{font-size:1.4em} */14px*/
li{font-size:1.4em} /*14px*/
li li{font-size:1.4em} /*20px*/
em is guided by the font-size of its parent and calculating it again and again can become frustrating at times.
rem has been introduced in CSS3 to overcome both the above mentioned limitations. It just behaves like em but the only difference is that rem values are based on the root element (html or body) and are not affected by the parent font-size value. So, if I use the above mentioned code for rem unit, it will be as follows..
body{font-size:62.5%}
p{font-size:1rem} /*10px*/
h1{font-size:1.4rem} */14px*/
li{font-size:1.4rem} /*14px*/
li li{font-size:1.4rem} /*14px*/
And the interesting thing is that it's supported by all modern browsers including IE9. Though Opera has not implemented rem unit yet. but you always have an option to use px as a fallback for the browsers not supporting rem unit.
p{font-size:14px; font-size:1rem}
So the browser supporting rem will use rem otherwise px will be used for the browsers not supporting rem.
px has been around ever since I started working and is most consistent and reliable. Most of the UI developers use it but if you are a usability concerned developer, you will not use it. Reason being, Internet explorer users can not use the browser default capabilities are increasing/decreasing the font size.
To over come the text-resizing issue in IE, em has been used for a long time. But the problem with the em based font-size is that the font-size is compound. See the example below. Using 62.5% for body so that I don't need to calculate the em value every time I need to use the unit.
body{font-size:62.5%}
p{font-size:1em} /*10px*/
h1{font-size:1.4em} */14px*/
li{font-size:1.4em} /*14px*/
li li{font-size:1.4em} /*20px*/
em is guided by the font-size of its parent and calculating it again and again can become frustrating at times.
rem has been introduced in CSS3 to overcome both the above mentioned limitations. It just behaves like em but the only difference is that rem values are based on the root element (html or body) and are not affected by the parent font-size value. So, if I use the above mentioned code for rem unit, it will be as follows..
body{font-size:62.5%}
p{font-size:1rem} /*10px*/
h1{font-size:1.4rem} */14px*/
li{font-size:1.4rem} /*14px*/
li li{font-size:1.4rem} /*14px*/
And the interesting thing is that it's supported by all modern browsers including IE9. Though Opera has not implemented rem unit yet. but you always have an option to use px as a fallback for the browsers not supporting rem unit.
p{font-size:14px; font-size:1rem}
So the browser supporting rem will use rem otherwise px will be used for the browsers not supporting rem.
No comments:
Post a Comment