CSS样式 - 百分比vs em vs px? [英] CSS style - percentes vs em vs px?
问题描述
在阅读网络上的几篇文章后,我对使用%
, em
code> px for div's
, input's
, font's
,按钮
等等...
对于我在工作的网站,我们不能添加响应式设计,从我从不同的文章比百分比的理解是的方式来去元素
和 div's
。但比我困惑,因为我认为即使我使用 px
för布局,并且设置不同的宽度,高度在 px
取决于设备/屏幕分辨率...?
有什么时候使用什么的最佳实践?不仅对于fontsize,而且对于 div的
和另一个元素?
长度
中的值%
, em
, px
, pt
只是不同的措施在你的CSS布局。没有规则可以使用它们。 事实上,很难告诉你你必须做什么,因为很难说出你要做什么每个布局。
我可以做的是告诉你,基本知识,但您可能已经知道了:您将有一些绝对值( cm
, mm
,在
, pt
, code> px
)和一些相对值(基于文本: em
, ex
, ch
, rem
; viewport based: vw
, vh
, vmin
, vmax
)。相对措施随着基础变化而改变。
我个人发现自己使用了很多常见的,绝对的。但我们永远不能告诉你你想要达到什么。因此,您可以随时使用官方文档,以便随时查找每个布局挑战的最佳方式。
运气!
After reading several articles on the web I´m a bit confused about when to use percent
, em
or px
for div´s
, input´s
, font´s
, buttons
and so on...
For the site I´m working on we wan´t to add a responsive design, and from what I understand from different articles than percent is the way to go for elements
and div´s
. But than I get confused because I´m thinking that I should be able to get a responsive design even if I use px
för layout and than set different width, height in px
depending on device/screen resolution...?
And is there a best practice for when to use what? And not only for fontsize, but for div´s
and another elements as well?
As far as I could realize, the length
values in %
, em
, px
, pt
are just different measures you have to apply to get things done in your CSS layout. There's no rule at all to use them.
Fact is, it's hard to tell you what you have to do with them because is hard to tell what you are to achieve in each of your layouts. Layouts are about creativity, and you can't just fix an approach to fit all of them.
What I can do is tell you the basics, but you probably already know it: you'll have some absolute values (cm
, mm
, in
, pt
, pc
, px
) and some relative values (text based: em
, ex
, ch
, rem
; viewport based: vw
, vh
, vmin
, vmax
). Relative measures changes as they "base" changes.
I personally found myself using a lot of the common, absolute ones. But we can never tell what you're trying to achieve. So its good to have the official documentation in hand so you can always find the best way for each of your layouts challenges.
Luck!
这篇关于CSS样式 - 百分比vs em vs px?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!