Font size in CSS - % or em?

后端 未结 8 1831
走了就别回头了
走了就别回头了 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:39

    Given that (nearly?) all browsers now resize the page as a whole, rather than just the text, previous issues with px vs. % vs. ems in terms of accessible font resizing are rather moot.

    So, the answer is that it probably doesn't matter. Use whatever works for you.

    % is nice because it allows for relative resizing.

    px is nice because it's fairly easy to manage expectations when using it.

    em can be useful when also used for layout elements as it can allow for proportional sizing related to the text size.

提交回复
热议问题