我有問題,我有一個固定的容器,在他們裏面我有絕對的div,我想設置.absolute
div height:100%;
爲容器div的全高(500px)。 下面是我試圖解決我的問題,這需要,因爲我想創建與切換容器的手機菜單,其重要的是我的手機屏幕高度爲100%
。爲什麼我不能使絕對的高度100%
https://jsfiddle.net/d1bh9ncs/
HTML
<div class="container">
<div class="fixed">
<div class="absolute">
</div>
</div>
</div>
CSS
.container{
width:100%;
height:500px;
background-color:#ddd;
}
.fixed{
position:fixed;
width:100%;
height:50px;
background-color:red;
top:8px;
left:8px;
right:15px;
}
.absolute{
position:absolute;
height:100%;
width:100%;
background-color:green;
top:51px;
left:0px;
}
你的.fixed div的高度爲50px,而你的.absolute div的100%相對於.fixed,所以他也有50px的高度。 – sticksu
你可以使用'height:100vh;'爲'。絕對' –