css - 什么 margin :5px 0; and margin:5px 0 0; mean?

标签 css

margin:5px 0;margin:5px 0 0 0; 还是 margin:5px 0 5px 0;

margin:5px 0 0;margin:5px 0 0 0; 的意思吗?

填充当然也一样。

此外,它在所有浏览器(包括 IE6)中是否一致?

最佳答案

根据 Box Model :

  • If there is only one value, it applies to all sides.
  • If there are two values, the top and bottom margins are set to the first value and the right and left margins are set to the second.
  • If there are three values, the top is set to the first value, the left and right are set to the second, and the bottom is set to the third.
  • If there are four values, they apply to the top, right, bottom, and left, respectively.
body { margin: 2em }         /* all margins set to 2em */
body { margin: 1em 2em }     /* top & bottom = 1em, right & left = 2em */
body { margin: 1em 2em 3em } /* top=1em, right=2em, bottom=3em, left=2em */

这是由 CSS 标准定义的,因此它应该在所有正确实现 CSS 的浏览器中保持一致。对于浏览器兼容性,请查看 blooberry 的 CSS Support Historyquirksmode .根据 blooberry 的说法,margin 最早是在 IE3 中实现的,所以 IE6 应该没问题。

关于css - 什么 margin :5px 0; and margin:5px 0 0; mean?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/819207/

相关文章:

css - 为大型设备制作页面时,我可以使用@media query max-width 进行响应吗?

html - 元素元素的 CSS 样式

html - 当内容溢出页面时使非环绕 div 展开

javascript - 如何在 Angular 1 中为动态的 div(重复元素)执行 $anchorscroll

css - Dreamweaver CS6格式源码CSS在:后添加空格

css - 为不同的背景颜色减轻悬停时的背景颜色

php - 在页面加载时继续 CSS 动画?

html - flex 容器中的可滚动元素无法跨浏览器工作

html - 如何在页面中心顶部显示一个div

javascript - onClientClick for asp :element within a listview