我正试图模仿this search results page的布局.我使用bootstrap词缀使所有内容都正常工作,除了页脚.当您滚动到我所链接的示例的底部时,页脚向上推送 map div.这是我不能理解的部分.当您向下滚动到我的示例时,它正好位于map div后面.如何让橙色页脚将 map div(#maptainer)向上推送?

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>

推荐答案

这就是我的解决方案,只是需要做出响应,并对affixtopbottom进行调整.

#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>

Css相关问答推荐

如何在CSS中使用nextJs来指定基色?

可折叠/可展开的数据表行:如何使Shadcn数据表中的可折叠内容全宽?

我的css是我的react 应用程序没有按预期工作

如何在不重叠侧边栏的情况下尽可能使元素居中?

如何缩小 Select 元素的背景图像?

如何增加 PrimeFlex 网格的间隙?

如何使用 ReactJS 使用 CSS 设置 map 容器的样式

当计算的宽度不准确时,如何在 cypress 中测试元素的宽度?

使用border-radius CSS时平滑边框

页脚上方的图像分隔线使用 ::before 伪元素

将 CSS 注入 Shadow 根.然而风格正在受到影响

重置子元素的不透明度 - Maple Browser (Samsung TV App)

为什么无论我做什么都不能改变复选框的 colored颜色 ?

HTML/CSS 中的单选/复选框对齐

输入/按钮元素不会在 flex 容器中缩小

以原始大小的 50% 显示图像

如何在 CSS 中延迟 :hover 效果?

将 webkit 滚动条样式应用于指定元素

更改 html 列表中项目符号的 colored颜色 ?

html元素(div)的全高,包括边框,填充和边距?