简体   繁体   English

CSS - 应该用于边距和填充

[英]CSS - should em be used for margin and padding

In my stylesheet I use em for font sizes. 在我的样式表中,我使用em来表示字体大小。

Is it bad practice to use this for padding and margin as well so that when the font scales the margin and padding will scale with it? 将此用于填充和边距也是不好的做法,这样当字体缩放边距并且填充将随之缩放?

I don't think that its a bad practice, but I don't think that most of developers will use it nowadays: some thought on it: 我不认为这是一个不好的做法,但我认为现在大多数开发人员都不会使用它:有人想到它:

I don't see how this is wrong? 我不明白这是怎么回事?

em is just a way of expressing the measuring method. em只是表达测量方法的一种方式。 you can use pixels, em, cm. 你可以使用像素,em,cm。

also the padding of a div will be measured the way you put it. div的填充也将按照你的方式进行测量。 so if you write em to the padding it will work just as good as if you put pixels, it's just the value of spacing that varies 因此,如果你将em写入填充它会像放置像素一样好,它只是间距的值变化

It totally depends on your need. 这完全取决于你的需要。 Em should be avoided because it depends on the native browser settings, but if you use px then css of the page will be cross browser compatible. 应避免使用Em,因为它取决于本机浏览器设置,但如果使用px,则页面的css将与浏览器兼容。

Please refer to this post : Why em instead of px? 请参考这篇文章: 为什么em而不是px? This post will tell you when to use EM and when PX. 这篇文章将告诉你什么时候使用EM和PX。

I usually use em for font size, height, width, padding, and margin. 我通常使用em来获取字体大小,高度,宽度,填充和边距。 I don't usually mess with line-height, but I'd use em for that too. 我通常不会使用行高,但我也会使用em。 This of course always depends on what's on the page; 这当然总取决于页面上的内容; gifs, pngs, and jpgs don't usually do so well with ems ;-) gifs,pngs和jpgs通常不能用ems做好;-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM