css - 将 min-height 设置为 100%,作为 min-height 为 100% 的容器的子级

标签 css

TL:博士;是否可以将 min-height:100% 的子级设置为 min-height:100%

我的#body-container是一个全 Angular 容器,而我的.bg-container只是一个920px容器。

As pen
作为片段

html,
body {
  height: 100%;
  background-color: black;
}

#body-container {
  min-height: 100%;
  background-color: red;
}

.bg-container {
  width: 920px;
  margin: 0 auto;
  background-color: blue;
  min-height: 100%;
}
<div id="body-container">
  
  <div class="bg-container">
    foo bar
  </div>
  
</div>

最佳答案

当然,只需将 height:100%overflow:auto 添加到 #body-container 即可:

html,
body {
  height: 100%;
  background-color: black;
}
#body-container {
  height: 100%;
  min-height: 100%;
  overflow:auto;
  background-color: red;
}
.bg-container {
  width: 920px;
  margin: 0 auto;
  background-color: blue;
  min-height: 100%;
}
<div id="body-container">

  <div class="bg-container">
    foo bar
  </div>

</div>

关于css - 将 min-height 设置为 100%,作为 min-height 为 100% 的容器的子级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34092285/

相关文章:

css - 忽略一列以计算 css 网格的最大内容

html - CSS 如何在悬停时将表格中的两行突出显示为一行?

jquery - 如何忽略/覆盖溢出 :hidden of parent div without access to its css

javascript - 我将如何实现非常简单的文本框提示,以使用 CSS/HTML 中的密码字段?

html - Bootbox:消息溢出

html - 防止 div 在有填充时垂直移动

ul#navigation li 上的 jquery hasClass "active"页面加载不起作用

html - 如何使div成为内联 block ?

html - 是否可以使用 Flexbox 来设置响应式功能列表的样式

css - 在 IE 中更改占位符文本的字体大小和边距