Why em instead of px?

后端 未结 15 1068
闹比i
闹比i 2020-11-22 06:38

I heard you should define sizes and distances in your stylesheet with em instead of in pixels. So the question is why should I use em instead of px when defining styles in c

15条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-22 07:30

    example:

    Code: body{font-size:10px;} //keep at 10 all sizes below correct, change this value and the rest change to be e.g. 1.4 of this value

    1{font-size:1.2em;} //12px

    2{font-size:1.4em;} //14px

    3{font-size:1.6em;} //16px

    4{font-size:1.8em;} //18px

    5{font-size:2em;} //20px

    body

    1

    2

    3

    4

    5

    by changing the value in body the rest change automatically to be a kind of times the base value…

    10×2=20 10×1.6=16 etc

    you could have the base value as 8px… so 8×2=16 8×1.6=12.8 //may be rounded by browser

提交回复
热议问题