我注意到我的 #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-top
或 margin-bottom
时没有任何意义。
编辑:请参阅下面@web-tiki 的评论,其中有关于 auto
和 margin-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/