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/

相关文章:

html - xtype-selectfield 中的选择栏实现与 datepickerfield 相同

html - Element不想绝对定位,ag-Grid中自定义cell editor

css - 网格元素的叠加

html - 更改移动设备的 HTML5 视频源

javascript - ReactJS - 如何检测何时在文件输入上单击取消?

javascript - 如何通过单击其 div 从 p 获取文本?

javascript - 如何使用 Javascript 本地存储来存储 HTML 文本框中的值?

html - 如何在导航栏上居中对齐图像,对于小型设备如何将其向左移动以适应内容?

css - 从顶部开始的绝对位置,水平居中的 div

css - 尝试设置 vaadin-date-picker 输入文本的样式