设计网页时应在CSS中使用哪个单位 [英] Which unit I should use in CSS when designing a web page
本文介绍了设计网页时应在CSS中使用哪个单位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经设计和开发了10多个站点,但是我仍然对应该使用的正确单元存有疑问.是px
,em
还是%
?
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 %
?
用于布局(尤其是用于集装箱箱)
推荐答案
取决于上下文的不同单位.如果有一个最适合每种情况的单位,那么就不会有那么多单位.
Different units depending on context. If there was one that was best for every situation, then there wouldn't be so many units.
根据经验法则:
如果您正在处理屏幕媒体:
If you are working on screen media:
- 使用
%
设置字体大小 - 对图像使用
px
- 将
px
,%
或em
用于包装盒尺寸 - 使用行高比例
- Use
%
for font sizes - Use
px
for images - Use
px
,%
, orem
for box sizes - Use ratios for line height
如果您使用的是打印介质:
If you are working in print media:
- 避免使用
px
(无论如何这都不是硬性规定)可能是明智的选择,其他一切都是公平的游戏.这实际上取决于您想要多少控制权.
- 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.
这篇关于设计网页时应在CSS中使用哪个单位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文