【问题标题】:Content overflows from 100% height DIV内容从 100% 高度 DIV 溢出
【发布时间】:2016-07-31 19:09:33
【问题描述】:

我想创建一个div

  1. 拉伸到浏览器窗口的 100% widthheight
  2. 使里面的所有内容垂直和水平居中,
  3. 拥有min-height = 所有内容+ 10%top&bottom padding

我已经编写了一些代码:

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 点 - 当缩小时,内容会溢出它周围的 divscreen

我尝试设置为.blah

height: auto;
min-height: 100% !important;
position: relative;

但它不适用于更大的分辨率 - div 大于浏览器 height

这个solution 不起作用。

我将非常感谢任何想法。

【问题讨论】:

    标签: html css overflow flexbox


    【解决方案1】:

    你只需要使用box-sizing:border-box

    html,
    body {
      height: 100%;
      margin: 0
    }
    .blah {
      display: flex;
      flex-direction: column;
      justify-content: center;
      text-align: center;
      background: #ffb3b3;
      min-height: 100%;
      padding: 10% 0;
      box-sizing: border-box;
    }
    <div class="blah">
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed maximus rhoncus erat sit amet ullamcorper. Cras quis vulputate ex, ut sollicitudin massa. Vivamus vitae ipsum posuere, eleifend quam quis, pulvinar tellus. Cras semper, lectus sit amet molestie
      
    </div>

    【讨论】:

    • 解释为什么这样修复它会非常有用
    猜你喜欢
    • 1970-01-01
    • 2012-02-04
    • 1970-01-01
    • 2013-12-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-22
    • 2019-07-17
    相关资源
    最近更新 更多