html - 使绝对div高度为100%

标签 html css

我有一个位置相对的父div和绝对定位的2个子div(左和右)。

div应为height: 100%,右div内容应动态更改。现在,当我滚动时,左子项保持较小(不是100%),而右div具有其高度。

父div顶部有一个水平导航栏。我尝试使用bottom: 0position: fixed,但是效果不好。

.left-sidebar {
    font-weight: 400;
    background-color: #B3E5FC;
    display:inline-block;
    width: 29%;
    left: 0;
    z-index: 2;
    box-shadow: 5px 10px 10px 0px grey;
    height: 92vh;
    position: absolute;
}

.right-content{
    display: inline-block;
   // height: 100%;
    position: absolute;
    left:0;
    right: 0;
    padding: 1em;
    min-width: 66%;
}

.main-parent {
    position: relative;
}


enter image description here

最佳答案

您不需要position:absolute,但需要将height:100%赋予body / html.main-parent



* {
  box-sizing: border-box
}
body,
html {
  margin: 0;
  height: 100%
}
.main-parent {
  height:100%
}
.left-sidebar {
  font-weight: 400;
  background-color: #B3E5FC;
  display: inline-block;
  vertical-align:top;
  width: 29%;
  box-shadow: 5px 10px 10px 0px grey;
  height: 100%;
}
.right-content {
  display: inline-block;
  height: 100%;
  padding: 1em;
  min-width: 66%;
  background:red
}

<div class="main-parent">
  <div class="left-sidebar">asda</div>
  <div class="right-content">dsdf</div>
</div>

关于html - 使绝对div高度为100%,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37499522/

相关文章:

javascript - 如何通过 JavaScript 设置输入隐藏字段的值?

javascript - jQuery 选择器返回什么样的对象?

javascript - 数字递增按钮

jquery - 从 Bootstrap 2 升级到 Bootstrap 3 后布局困惑

jquery - Bootstrap 工具提示在 IE-8 到 IE-11 的页面滚动时未关闭

jquery - HTML5 视频不能在 IE 中在线播放,但可以离线播放

javascript - 如何阻止图像随其所在的 div 一起消失?

css - 为什么我们在normalize.css中加入这行代码?

jquery - 如何通过 jQuery 设置灵活的盒子 CSS? css( display, '-moz-box' ) 似乎不起作用?

css - Nth-child 以其他每个 child 为目标,但总是包括最后一个