2015-05-28
Yesterday saw a good pure CSS3 table style, see the code after notice that the author is using EM in the control size. Immediately think of their own accustomed to use the PX length unit, the difference between the two looked up. The summary records of the seniors were collated for their own study.
What is EM?
EM refers to the high font size, the default font for any browser is 16px. So the unmodified browser fits: 1em=16px. So 12px=0.75em, 10px=0.625em. To simplify the conversion of font-size, you need to declare font-size=62.5% in the body selector in the CSS, which makes the EM value 16px*62.5%=10px, so 12px=1.2em, 10px=1em, That means you just have to divide your original PX value by 10 and then put EM in as the unit. EM has the following characteristics:
1. The value of EM is not fixed;
2. Em inherits the font size of the parent element.
What is PX?
The PX length unit value is fixed, the specified amount is how much, calculation is easier.
Key points :
1. ie cannot adjust font sizes that use PX as the unit;
2. Most websites abroad can be adjusted because they use EM as font units;
3. Firefox can adjust px and em, but more than 96% of Chinese netizens use IE (or kernel).
px pixels (Pixel). Relative length units. Pixel px is relative to the display screen resolution.
em is a relative length unit. The font size relative to the text within the current object. If the current font size for inline text is not artificially set, the default font size for the browser is .
So when we are writing CSS, we need to pay attention to two points :
1. Declare font-size=62.5% in the body selector;
2. Divide your original PX value by 10 and then replace it with EM as the unit;
3. Recalculate the EM values of the enlarged fonts. Avoid duplicate declarations of font size.
This is to avoid the 1.2 * 1.2 = 1.44 phenomenon. For example, when you declare a font size of 1.2em in #content, you can only have 1em when declaring the font size of p, not 1.2em, because this em is not em, it becomes 1em=12px because it inherits the font height of #content.
However, 12px Kanji exception, is obtained by the above method 12px (1.2em) size of Chinese characters in IE does not equate directly with 12px defined font size, but slightly larger. This problem Jorux has been solved, just in the body selector to change 62.5% to 63% can be displayed normally. The reason may be that when IE processes Chinese characters, the accuracy of the value of floating point is limited. I wonder if there is any other explanation.
To see the specific differences, you can look at the example written by this predecessor: http://www.cnblogs.com/CherryGhost/archive/2011/09/29/2195451.html
The difference between PX and em in CSS fonts