0
我有一個垂直分隔爲兩個窗格的頁面。左側佈局很好,但我無法獲取內容以填充右側的可用空間。以下是說明這一點的圖表。 div內的內容不會填充可用空間而不指定高度
頁眉和頁腳(聚合物元素)是固定的高度,其中的內容區域在頁面視圖之間換出。爲了獲得內容填充空間,我必須指定以vh爲單位的主容器div高度。這在一定程度上有效,但我想用百分比來使它更加靈活,但似乎並不奏效。任何想法如何更好地解決這個問題?我的代碼如下。謝謝。
<style>
paper-card {
width:100%;
}
.mainContainer{
display: flex;
height:100%;
flex-direction: row;
flex-wrap: nowrap;
justify-content: flex-start;
}
.leftWindow {
display:flex;
height:100%;
width:550px;
padding-left: 10px;
padding-right: 10px;
}
.leftContainer{
display: flex;
height:100%;
flex-direction: column;
flex-wrap: nowrap;
justify-content: flex-start;
}
.rightContainer{
display: flex;
height:100%;
flex-direction: column;
flex-wrap: nowrap;
justify-content: flex-start;
}
.rightWindow {
flex-grow: 1;
height:100%;
padding-right: 10px;
}
.notificationBlock{
display:flex;
flex:2 0 0;
background-color: #009900;
}
.controlPanelBlock{
height:60px;
margin-bottom: 25px;
}
#divMainContainer {
position: relative;
display: block;
width: 100%;
height: 80vh;
}
.divModeImage {
display:flex;
flex-flow: row wrap;
width: 30%;
height: 16vw;
flex-grow: 1;
margin-top: 1vmin;
margin-left: 1em;
margin-right: 1em;
margin-bottom: 2vmin;
}
</style>
<div class="mainContainer">
<div class="leftWindow">
<div class="leftContainer">
other stuff. Left side displays fine
</div>
</div>
<div class="rightWindow">
<div class="rightContainer">
<notifications class="notificationBlock">
<paper-card id="pcNotifcationBar" heading=" ">
<view-content notification={{notification}}>
<!-- Content changes here depending on page -->
<div id="divMainContainer"> <!-- class is using height: 80vh -->
<!-- 1st row of three images -->
<div class="divModeImage"> <!-- class is using height: 16vw -->
<iron-image id="imgBefore1" class="cabinModeImage"></iron-image>
</div>
<div class="divModeImage"> <!-- class is using height: 16vw -->
<iron-image id="imgBefore2" class="cabinModeImage"></iron-image>
</div>
<div class="divModeImage"> <!-- class is using height: 16vw -->
<iron-image id="imgBefore3" class="cabinModeImage"></iron-image>
</div>
<!-- 2nd row of three images -->
<div class="divModeImage"> <!-- class is using height: 16vw -->
<iron-image id="imgAfter1" class="cabinModeImage"></iron-image>
</div>
<div class="divModeImage"> <!-- class is using height: 16vw -->
<iron-image id="imgAfter2" class="cabinModeImage"></iron-image>
</div>
<div class="divModeImage"> <!-- class is using height: 16vw -->
<iron-image id="imgAfter3" class="cabinModeImage"></iron-image>
</div>
</div>
<!-- Content changes here depending on page -->
</view-content>
</paper-card>
</notifications>
<footer class="controlPanelBlock" style="margin-top:10px;"></footer>
</div>
</div>
</div>
您可能只需要添加'高度:100%'到要上使用百分比高度元素的任何父。百分比高度相對於容器。你也可能需要或不需要添加'html,body {height:100%; }' –
如果我明白這一點..你是否希望綠色區域應該完全填充它..'#divMainContainer {display:block; 身高:100%; 位置:相對; 寬度:100%; }' – Aniket
請發佈一個問題的工作示例。 –