【发布时间】:2021-03-06 19:21:11
【问题描述】:
我有一个包含多个列、一个页眉和一个页脚的页面。我希望列与用户一起滚动,但不与页脚重叠:
<html>
<head></head>
<body>
<div id="wrap">
<div id="main" class="clear-top">
<div class="col-lg-12">
<div class="row pl-4 justify-content-between pb-4">
<div class="col-lg-1 col-md-12 col-sm-12 ">
</div>
<div class="col-lg-7 col-md-12 col-sm-12 ">
... Main Content ...
</div>
<div class="col-lg-4 col-md-12 col-sm-12 p-4 sidebar-container">
... Content I want to Scroll with User ...
</div>
</div>
</div>
</div>
</div>
</body>
<footer class="footer">
<div class="container">
</div>
</footer>
</html>
CSS:
// General Styling
html, body{
height: 100%;
}
#wrap {
min-height: 100%;
}
#main {
overflow:auto;
padding-bottom:150px; /* this needs to be bigger than footer height*/
}
.footer {
position: relative;
margin-top: -150px; /* negative value of footer height */
height: 150px;
clear:both;
padding-top:20px;
width: 100%;
bottom: 0;
}
我使用的是 Bootstrap 4,所以我尝试将 sticky-top 类添加到我想要滚动的列中,但没有任何改变。
我尝试将列的position 更改为sticky,但似乎没有任何变化。我是否将其添加到错误的 div 中?
【问题讨论】:
-
对于初学者,我注意到您的 HTML 有几个错误:这是您的 html 的清理版本。 jsfiddle.net/d75qh3fx
-
footer应该在body内。列必须是row的直接子代,而不是父列的直接子代。
标签: css bootstrap-4 sticky