如何使 child div 匹配滚动高度 parent?
How do I make a child div match the height of scrolling parent?
如何通过在 body 上滚动使 div 和嵌套的 div 向下延伸到屏幕的整个高度?
Link 到 fiddle: https://jsfiddle.net/qsczjd01/
CSS:
#megaAll{
box-sizing: border-box;
position: absolute;
background-color: gray;
top: 0px;
bottom: 0px;
left: 0px;
right: 0px;
}
我需要#megaAll(灰色)、#megaMain(粉红色)和#contentContainer 一直延伸到页面下方,但由于在 [=24 上滚动,它似乎无法延伸到全高=].我需要 body 上的滚动和右侧的固定侧边栏保持不变。
往下延伸就是height:auto;无需提及,因为它是默认设置。无论您的身高是多少,它都会自动调整整个页面。
"sidebar on the right to remain" 表示已修复,如果我猜对了,这会起作用。
position: fixed;
使用
position: fixed;
相反。这会将元素固定在 window 中,而不是固定在 body 元素中。
想通了!我将 divs 从使用 position: absolute 和 0px 改为使用边距为 0px 的静态定位。
新例子div:
#megaAll{
box-sizing: border-box;
background-color: gray;
margin: 0 auto;
}
更多信息在这里:
如何通过在 body 上滚动使 div 和嵌套的 div 向下延伸到屏幕的整个高度?
Link 到 fiddle: https://jsfiddle.net/qsczjd01/
CSS:
#megaAll{
box-sizing: border-box;
position: absolute;
background-color: gray;
top: 0px;
bottom: 0px;
left: 0px;
right: 0px;
}
我需要#megaAll(灰色)、#megaMain(粉红色)和#contentContainer 一直延伸到页面下方,但由于在 [=24 上滚动,它似乎无法延伸到全高=].我需要 body 上的滚动和右侧的固定侧边栏保持不变。
往下延伸就是height:auto;无需提及,因为它是默认设置。无论您的身高是多少,它都会自动调整整个页面。 "sidebar on the right to remain" 表示已修复,如果我猜对了,这会起作用。
position: fixed;
使用
position: fixed;
相反。这会将元素固定在 window 中,而不是固定在 body 元素中。
想通了!我将 divs 从使用 position: absolute 和 0px 改为使用边距为 0px 的静态定位。
新例子div:
#megaAll{
box-sizing: border-box;
background-color: gray;
margin: 0 auto;
}
更多信息在这里: