词缀导航栏跳转

时间:2018-12-23 16:06:59

标签: html css twitter-bootstrap-3

我在使用bootstrap词缀时遇到了问题,并且停留了两天,因此我需要您的重要帮助。

我是网络开发人员的新手,请原谅我的转储问题。我玩着有关词缀(粘性导航栏)的w3schools示例

就我而言,我想将导航栏保持在屏幕底部,并且在用户滚动时,我希望导航栏变得粘稠。

我已经尝试了百万种方法来避免导航栏跳动,但是没有成功。

当我尝试在容器流体类中设置高度:vh时出现问题。我试图设置没有运气的百分比。

由于我请求您的帮助,我认为我的方法不正确。

欢迎任何建议:)

<!DOCTYPE html>
<html>
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  <style>
  /* Note: Try to remove the following lines to see the effect of CSS positioning */
  .affix {
    top: 0;
	position: fixed;
    width: 100%;
    z-index: 9999 !important;
  }

  .affix + .container-fluid {
    padding-top: 1000px;
  }
	  
	  .container-fluid{
		  height: 100vh;
	  }
	  
	  .body{
		  height: 100%;
	  }

  </style>
</head>
<body>

<div class="container-fluid" style="background-color:#F44336;color:#fff;">
  <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" 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" style="height:1000px">
  <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>

</body>
</html>

1 个答案:

答案 0 :(得分:1)

您可以使用粘性位置。像这样:

  .affix {
    top: 0;
    position: sticky;
    width: 100%;
    z-index: 9999 !important;
  }