1. 程式人生 > >知識普及之:CSS: body{font-size: 62.5%;}這種寫法為什麼???

知識普及之:CSS: body{font-size: 62.5%;}這種寫法為什麼???

CSS: body{font-size: 62.5%;}為什麼???

在網頁設計中我們經常看見body{font-size: 62.5%;}這樣的設定,為什麼偏偏是62.5%呢?這主要是為了方便em與px相互轉換,em的初始值為1em=16px,顯然這樣的話,如1.2em則=19.2px,可是我們在設定的時候很少看見19.2px這樣表示的大小,也就是在用px表示大小時數值是不帶小數位的。當設定了body{font-size: 62.5%;}時,1em則=16px*62.5%=10px,1.2em則=12px,這是不是就簡單多了,準確多了呢~~

Set body font-size to 62.5% for Easier em Conversion

If you would like to use relative units (em) for your font sizes, declaring 62.5% for the font-size property of the body will make it easier to convert px to em. By doing it this way, converting to em is a matter of dividing the px value by 10 (e.g. 24px = 2.4em).

code:

body {
  font-size: 62.5%;
}
p {
  font-size: 1.2em;
}