html - 为什么 height 100% 不能将 div 完全扩展到页面底部?

标签 html css

我希望 #f8f8f8 延伸到页面底部。我尝试将 height: 100%; 添加到 .tab-content 但没有任何反应。

有什么建议吗?

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
}

.tab-container {
  color: #fff;
  background: #000;
}

.tab-content {
  background: #f8f8f8;
  height: 100%; /* doesn't work */
}
<div class="vreditor-sdk">
  <div class="building">
    <div class="header"></div>
    <div class="i-tab">
      <div class="tab-container">
      </div>
      <div class="tab-content">
        Test
      </div>
    </div>
  </div>
</div>

最佳答案

在 css 中,当您以百分比形式给出高度时,它将采用父高度的百分比。

height: 100%; 赋给 .tab-content 意味着它占用 .itab100% 高度> 不是页面。所以如果你想让你的 .tab-content 覆盖整个页面,你的 .itab 需要先覆盖整个页面。在到达 html 元素之前,每个直接父级都会发生同样的情况。

所以你的修复应该是

html, body, .vreditor-sdk, .building, .itab, .tab-content {
    height: 100%:
}

html 占页面的 100% 高度,body 占 html 的 100% 高度,与页面高度等同......

这就是您的页面高度如何到达您的.tab-content

关于html - 为什么 height 100% 不能将 div 完全扩展到页面底部?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50211086/

相关文章:

html - 高度 : 100% for anchor tag inside table cell keeping vertical-align

javascript - 选中自定义单选按钮时更改另一个 div 中 anchor 标记的颜色

javascript - 使用 ASP.net 控件和 Telerik 控件禁用表

javascript - 使 <li> 标签可编辑

css - 更改原子编辑器的光标样式

html - 如何通过使用 :focus? 更改其属性使字段保持在同一个位置

css - IE 6,7 是否支持背景颜色 :inherit; for CSS?

javascript - 为什么我的 HTML 文件有时只能正确加载?

html - Chrome 在使用 CSS background-size :cover in scrolling background image 时滞后

html - IE 11 中的不同 IE5-Quirks-Mode?