简体   繁体   English

使绝对div高度为100%

[英]Make absolute div height 100%

I have a parent div with position relative and 2 child divs (left and right) with absolute positioning. 我有一个位置相对的父div和绝对定位的2个子div(左右)。

Left div should be of height: 100% and right div content changes dynamically. divheight: 100%应为height: 100% ,右div内容会动态更改。 Now when I scroll left child remains smaller (not 100%) and right div had its height. 现在,当我滚动时,左子项保持较小(不是100%),而右div具有高度。

There is horizontal navigation-bar on top of parent div. 父div顶部有水平导航栏。 I tried with bottom: 0 , position: fixed , but results are not good. 我尝试使用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;
}

在此处输入图片说明

you don't need position:absolute but you need to give height:100% to body / html and .main-parent 您不需要position:absolute但您需要为body / html.main-parent赋予height:100%

 * { 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> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM