[英]ScrollY/ScrollTop doesn't work when height of html and body is 100%
[英]CSS Height 100% doesn't work when overflowed
發生的是這段代碼:
的HTML
<div class="one">
<div class="will-overflow">
</div>
</div>
的CSS
html, body {
width: 100%;
height: 100%;
}
.one {
height: 100%;
background: red;
}
.one .will-overflow {
width: 20%;
height: 2000px;
background: blue;
}
我得到這樣的結果:
演示版
題
無論如何,有沒有擴大div.one高度以適合div.will-overflow 。 這只是一個示例,該div的內容是動態的。
html, body {
width: 100%;
height: 100%;
}
.one {
min-height: 100%;
background: red;
}
.one .will-overflow {
width: 20%;
height: 1000px;
background: blue;
}
通過將.one
的height
更改為min-height
,可以使其具有彈性。 但是,現在的height: 100%
.will-overflow
height: 100%
不起作用,因為如果沒有任何拉伸的方式, .one
高度將為0; 所以我將height
更改為1000px
以模擬一些任意長度的內容。 將其更改為一個較小的值(如10px
以檢查它仍然允許.one
填充整個視口。
正確的高度是100%。
.one .will-overflow {
width: 20%;
height: 120%;
background: blue;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.