html - margin-bottom : auto calculated?如何

标签 html css margin

我注意到我的 #thing div 下有很多空白空间。我的 #thing 边距设置为 margin: 100px auto;,所以我将其更改为 margin: 100px auto 0px auto;,然后为空空间消失了。为什么将 margin-bottom 设置为 auto 会产生一堆空白?它不仅仅是试图填充可见屏幕,因为我的 div 超出了我的屏幕高度;我必须向下滚动才能看到空白区域。

最佳答案

简写 margin: 100px auto; 扩展为 margin: 100px auto 100px auto; 意思是:

margin-top: 100px;
margin-right: auto;
margin-bottom: 100px;
margin-left: auto;

所以你没有看到额外的空间,因为 margin-bottom: auto;。事实上,值 auto 在分配给 margin-topmargin-bottom 时没有任何意义。

编辑:请参阅下面@web-tiki 的评论,其中有关于 automargin-top 的用例margin-bottom

作为引用,margin 的简写选项是:

margin: [top] [right] [bottom] [left];
margin: [top] [right/left] [bottom];
margin: [top/bottom] [left/right];

关于html - margin-bottom : auto calculated?如何,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28623598/

相关文章:

javascript - 如何将 csv 文件中的数据加载到表单字段中?

javascript - 重新选择并上传相同的文件

html - 表格下的按钮对齐在 CSS 中不起作用

asp.net - 密码强度定位问题

c# - 如何单独设置 StackPanels 边距?

javascript - HTML Bootstrap 边框/面板

html - 将div内容拉伸(stretch)到页面底部固定位置页脚

javascript - StackExchange/Facebook 类通知框定位

jquery - Firefox 中的负边距不起作用

html - 设置 margin 为 auto 的要求