html - 贴上导航栏跳转

标签 html css twitter-bootstrap-3

我对 Bootstrap affix 有疑问。我想让导航栏粘在屏幕底部,我正在关注有关 affix 的 w3schools 示例,但导航栏一直在跳动。

当我尝试在 container-fluid 类中设置 height : 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>

最佳答案

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

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

关于html - 贴上导航栏跳转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53905104/

相关文章:

html - 纯 CSS 上下文高亮

html - 显示图例文本时防止容器增长

CSS网格和指定多个区域

javascript - 如何弹出错误 Bootstrap ?

ios - (响应)表格宽度不适合 ios safari 上 iframe 内的容器

css - 文本从容器 div 中出来

html - 使用 Swift 从网站解析表格数据

html - Excel 到 HTML 表格

html - 在 SharePoint 2010 中导入 CSS

css - Safari 与 Chrome/Firefox : border-image vs border-color