我正在尝试模仿这个搜索结果页面的布局。除了页脚之外,我的所有内容都使用 bootstrap 词缀。当您在我链接的示例中滚动到底部时,页脚会向上推地图 div。那是我无法弄清楚的部分。当您向下滚动我的示例时,它就在地图 div 后面。如何让橙色页脚将地图 div (#mapcontainer) 向上推?
CSS
#topmenu.affix {
top: 0;
width: 100%;
z-index: 9999 !important;
}
#mapcontainer {
background: lightgray;
margin-top: -20px;
width: 100%;
height: 100%;
overflow: hidden;
}
#mapcontainer.affix {
top: 72px;
z-index: 9999 !important;
}
#topmenu.affix + .container-fluid {
padding-top: 70px;
}
/*
#mapcontainer.affix + .container-fluid {
padding-top: 100px;
background: lightgray;
}
*/
footer {
height: 100px;
background-color: orange;
}
.container-fluid{
padding-right: 0px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div class="container-fluid" style="background-color:#F44336;color:#fff;height:200px;">
<h1>Bootstrap Affix Example</h1>
<h3>Fixed (sticky) navbar on scroll</h3>
<p>Scroll this page to see how the navbar behaves with data-spy="affix".</p>
<p>The navbar is attached to the top of the page after you have scrolled a specified amount of pixels.</p>
</div>
<nav class="navbar navbar-inverse" id="topmenu" data-spy="affix" data-offset-top="197">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Basic Topnav</a></li>
<li><a href="#">Page 1</a></li>
<li><a href="#">Page 2</a></li>
<li><a href="#">Page 3</a></li>
</ul>
</nav>
<div class="container-fluid">
<div class="row">
<div class="col-sm-3">
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
</div>
<div class="col-sm-9" >
<div id="mapcontainer" data-spy="affix" data-offset-top="200">
<h1>map area</h1>
<h1>map area</h1>
<h1>map area</h1>
<h1>map area</h1>
<h1>map area</h1>
<h1>map area</h1>
<h1>map area</h1>
<h1>map area</h1>
<h1>map area</h1>
<h1>map area</h1>
<h1>map area</h1>
<h1>map area</h1>
<h1>map area</h1>
<h1>map area</h1>
<h1>map area</h1>
<h1>map area</h1>
<h1>map area</h1>
<h1>map area</h1>
<h1>map area</h1>
<h1>map area</h1>
<h1>map area</h1>
<h1>map area</h1>
<h1>map area</h1>
</div>
</div>
</div>
</div>
<footer class="bg-light text-center text-lg-start" id="footer">
<div class="text-center p-3">
hello
</div>
</footer>
</body>
</html>
它只是关于位置:粘性;在地图区域容器上,当你滚动两个不同的内容(右边的地图区域和左边的一些文本项目)时,你认为页脚会向上推地图区域。
#topmenu.affix {
top: 0;
width: 100%;
z-index: 9999 !important;
}
.d-flex {
display: flex;
/* flex-direction: row-reverse; */
justify-content: space-between;
}
#mapcontainer {
background: lightgray;
height: 100vh;
width: 50%;
position: sticky;
top: 85px;
}
#topmenu.affix+.container-fluid {
padding-top: 70px;
}
/*
#mapcontainer.affix + .container-fluid {
padding-top: 100px;
background: lightgray;
}
*/
footer {
height: 400px;
background-color: red;
}
.container-fluid {
padding-right: 0px;
}
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container-fluid" style="background-color:#F44336;color:#fff;height:200px;">
<h1>Bootstrap Affix Example</h1>
<h3>Fixed (sticky) navbar on scroll</h3>
<p>Scroll this page to see how the navbar behaves with data-spy="affix".</p>
<p>The navbar is attached to the top of the page after you have scrolled a specified amount of pixels.</p>
</div>
<nav class="navbar navbar-inverse" id="topmenu" data-spy="affix" data-offset-top="197">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Basic Topnav</a></li>
<li><a href="#">Page 1</a></li>
<li><a href="#">Page 2</a></li>
<li><a href="#">Page 3</a></li>
</ul>
</nav>
<div class="container-fluid">
<div class="row d-flex">
<div class="col-sm-3">
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
</div>
<div id="mapcontainer" data-spy="affix" data-offset-top="200">
text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1> text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
</div>
</div>
</div>
<footer class="bg-light text-center text-lg-start" id="footer">
<div class="text-center p-3">
hello
</div>
</footer>
</body>
</html>
这是我的解决方案,只需要做出响应,并使用
affix
的 top
和 bottom
进行调整。
#topmenu.affix {
top: 0;
width: 100%;
z-index: 10000 !important;
}
#mapcontainer {
background: lightgray;
margin-top: -20px;
width: 100%;
height: 100%;
overflow: hidden;
}
#topmenu.affix+.container-fluid {
padding-top: 70px;
}
footer {
height: 100px;
background-color: orange;
}
.container-fluid {
padding-right: 0px;
}
/*new code*/
.container-fluid .col-sm-9 {
position: sticky;
height: calc((100vh - 70px) - 0px);
top: 70px;
}
#mapcontainer.affix {
top: -20px;
z-index: 9999 !important;
position: relative;
height: calc((100vh - 20px) - 10px);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div class="container-fluid" style="background-color:#F44336;color:#fff;height:200px;">
<h1>Bootstrap Affix Example</h1>
<h3>Fixed (sticky) navbar on scroll</h3>
<p>Scroll this page to see how the navbar behaves with data-spy="affix".</p>
<p>The navbar is attached to the top of the page after you have scrolled a specified amount of pixels.</p>
</div>
<nav class="navbar navbar-inverse" id="topmenu" data-offset-top="197" data-spy="affix">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Basic Topnav</a></li>
<li><a href="#">Page 1</a></li>
<li><a href="#">Page 2</a></li>
<li><a href="#">Page 3</a></li>
</ul>
</nav>
<div class="container-fluid">
<div class="row">
<div class="col-sm-3">
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
</div>
<div class="col-sm-9">
<div id="mapcontainer" data-spy="affix" data-offset-top="200">
<h1>map area</h1>
<h1>map area</h1>
<h1>map area</h1>
<h1>map area</h1>
<h1>map area</h1>
<h1>map area</h1>
<h1>map area</h1>
<h1>map area</h1>
<h1>map area</h1>
<h1>map area</h1>
<h1>map area</h1>
<h1>map area</h1>
<h1>map area</h1>
<h1>map area</h1>
<h1>map area</h1>
<h1>map area</h1>
<h1>map area</h1>
<h1>map area</h1>
<h1>map area</h1>
<h1>map area</h1>
<h1>map area</h1>
<h1>map area</h1>
<h1>map area</h1>
</div>
</div>
</div>
</div>
<footer class="bg-light text-center text-lg-start" id="footer">
<div class="text-center p-3">
hello
</div>
</footer>
</body>
</html>