The difference between EM, REM, and PX in CSS and the pros and cons of each
Source: Internet
Author: User
Px:
PX is actually a pixel, which is more stable and precise when setting the font size with PX. However, there is a problem with this approach, when users browse our web pages in a browser, and if they change the zoom of the browser, then the layout of our web page is broken. This is a big problem for users who are concerned about the usability of their website. Therefore, it is proposed to use "em" to define the font of the Web page.
Em:
EM is the size of the font that is scaled based on the datum. The EM essence is a relative value, not a specific number. This technique requires a reference point, which is generally based on the "font-size" of <body>. such as the official WordPress theme Twenntytwelve benchmark is 14px=1em.
In addition, EM is calculated relative to the attributes of the parent element, if you want to calculate the conversion between PX and EM, this site is good, the input data can be PX and EM mutual calculation. Hit here: px and EM conversions
Rem:
EM is relative to its parent element to set the font size, so there is a problem, any element setting, it may be necessary to know the size of his parent element. While REM is relative to the root element
Browser compatibility
In addition to IE6-IE8R, other browsers support both EM and REM properties, and PX is supported by all browsers.
Therefore, for browser compatibility, "px" and "REM" can be used together, "px" to achieve ie6-8 effect, and then use "REM" to achieve the effect of the browser.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.