【发布时间】:2016-07-31 19:09:33
【问题描述】:
我想创建一个div:
- 拉伸到浏览器窗口的 100%
width和height, - 使里面的所有内容垂直和水平居中,
- 拥有
min-height= 所有内容+10%的top&bottompadding。
我已经编写了一些代码:
html {
height: 100%;
}
body {
height: 100%;
}
.blah {
display: flex;
flex-direction: column;
width: 100%;
height: 100%;
justify-content: center;
text-align: center;
padding: 10% 0 10% 0;
background: #ffb3b3;
}
<div class="blah">
<p>Here goes some content</p>
</div>
jsfiddle也一样
如您所见,它工作正常,除了 第 3 点 - 当缩小时,内容会溢出它周围的 div:
screen
我尝试设置为.blah:
height: auto;
min-height: 100% !important;
position: relative;
但它不适用于更大的分辨率 - div 大于浏览器 height。
这个solution 不起作用。
我将非常感谢任何想法。
【问题讨论】: