What em can do which can't be done by %?
What em
can do which ca开发者_Go百科n't be done by %
?
Ems are useful because they're very high precision and directly related to the font size.
Check out the always-insightful A List Apart for some good advice.
Each offers a different way of determining a value, and each has certain advantages/disadvantages. These also vary depending on the particular property in question.
For font-sizing, there's little to differentiate the two: both will size the font relative to its parent's font, and both use the same value (<number>) so should be equally precise.
For other properties, such as width, the difference is very significant. Percentage values effectively provide the ability to vary according to window size. Em-based values allow you to vary dimensions according to font-size. The former is great for handling a range of output devices. The latter is great at maintaining consistent line lengths.
精彩评论