使用保证金和保证金时应该考虑什么?填充空间元素?
我的任务是修改网站的布局,使其符合客户公司风格指南的标准。
该指南要求我确保某些元素与其他元素间隔 [X]px,并且该类型的元素与该类型的元素对齐。
因此,当我这样做时,我可以看到现有间距在某些情况下使用 padding
定义,而在其他情况下使用 margin
定义。
有这样做的首选方法吗?我什么时候应该使用其中一种而不是另一种?
I have been tasked with modifying the layout of a site so that it meets the criteria of the client's corporate style guide.
The guide is requiring that I ensure certain elements are spaced [X]px from other elements, and that elements of this type are lined up with elements of that type.
So as I'm doing this, I can see that the existing spacings are defined in some cases using padding
, and in other cases using margin
.
Is there a preferred way of doing this? When should I use one in favour of the other?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
通俗地说。
如果您有两个相邻的 div,则两者之间的空间称为边距。
如果 div 中有文本,则 div 边缘(上、右、下、左)和文本之间的空间称为内边距。
In layman terms.
If you have two div's next to one another, the space between the two is referred to as the margin.
If you have text inside a div, the space between the edge of the div(top,right,bottom,left) and text is referred to as padding.
这确实取决于某种程度。边距和填充是两个不同的东西。但在某些情况下,您不会注意到差异。
显示差异的图:
来源:http://www.edition-w3c.de/TR/1998/REC-CSS2-19980512/bilder/boxdim.gif
例如:如果你想定义边框和你的边框之间的空间内容你只能通过填充来实现这一点(同时具有可见的边框)。
That really depends somehow. Margin and Padding are two different things. However in some cases you will not notice a difference.
A figure which shows you the difference:
Source: http://www.edition-w3c.de/TR/1998/REC-CSS2-19980512/bilder/boxdim.gif
So for example: If you want to define the space between the border and your content you will only achieve this with padding(while having a visible border).
这种差异最好通过视觉来解释。
尝试一下:
您应该会看到边距只是移动了 div,而内边距实际上使其变大了。
The difference is best explained visually.
Try this out:
You should see that the margin is simply moving the div, and the padding is actually making it larger.