Which unit I should use in CSS when designing a web page

后端 未结 6 1572
臣服心动
臣服心动 2020-12-05 10:49

I have designed and developed more than 10 sites, but I still have a doubt about the correct unit I should use. Should it be px, em or %

6条回答
  •  一个人的身影
    2020-12-05 11:26

    There's no real right or wrong, but as a rule of thumb:

    • For anything you want a certain, fixed size, use PX
    • For anything you want to scale with font-size, use EM
    • For anything you want to scale to the available space in the window/container, use %

    Each used to have specific advantages or disadvantages in different browsers when it came to users scaling the browser's base font-size/zooming, but more recent versions of the browsers by-and-large get around these issues by scaling everything, not just font-size.

提交回复
热议问题