Font size in CSS - % or em?

后端 未结 8 1832
走了就别回头了
走了就别回头了 2020-11-28 02:24

When setting the size of fonts in CSS, should I be using a percent value (%) or em? Can you explain the advantage?

8条回答
  •  遥遥无期
    2020-11-28 02:50

    As Galwegian mentions, px is the most reliable for web typography, as everything else you do on the page is mostly laid out in reference to a computer monitor. The problem with absolute sizes is that some browsers (IE) won't scale pixel-value elements on a web-page, so when you try to zoom in/out, everything adjusts except for those elements.

    I do not know whether IE8 handles this properly, but all other browser vendors handle pixels just fine and it is still a minority case where a user needs to enlarge/diminish text (this text box on SO perhaps being the exception). If you want to get really dirty, you could always add a javascript function for making your text size larger and offer a "small"/"larger" button to the user.

提交回复
热议问题