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

后端 未结 6 1577
臣服心动
臣服心动 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:36

    Different units depending on context. If there was one that was best for every situation, then there wouldn't be so many units.

    As rules of thumb go:

    If you are working on screen media:

    • Use % for font sizes
    • Use px for images
    • Use px, %, or em for box sizes
    • Use ratios for line height

    If you are working in print media:

    • It might be wise to avoid px (this is not a hard rule by any means) and everything else is fair game. It really depends how much control you want.

提交回复
热议问题