Why em instead of px?

后端 未结 15 1275
闹比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:25

    I have a small laptop with a high resolution and have to run Firefox in 120% text zoom to be able to read without squinting.

    Many sites have problems with this. The layout becomes all garbled, text in buttons is cut in half or disappears entirely. Even stackoverflow.com suffers from it:

    Screenshot of Firefox at 120% text zoom

    Note how the top buttons and the page tabs overlap. If they would have used em units instead of px, there would not have been a problem.

提交回复
热议问题