简体   繁体   English

如何在不使用固定顶部导航栏的情况下让 Bootstrap 导航栏在内容前面展开

[英]How to get Bootstrap navbar to expand in front of content without using a fixed-top navbar

I'm trying to get my bootstrap navbar to expand in front of the page content.我试图让我的引导导航栏在页面内容前面展开。 Currently, when the viewport get small enough and it collapses in to the hamburger toggle, upon expansion it shifts the content of the page down.目前,当视口变得足够小并且它折叠到汉堡切换时,在展开时它会向下移动页面的内容。 I would like for it to expand in front of the content instead of shifting everything down.我希望它在内容之前扩展,而不是向下移动所有内容。 I saw some similar posts that said you can achieve this using the "fixed-top" classes added to the navbar - I tried that and it did work, but I would prefer to not have the navbar bar fixed-top, and cannot figure out how to have it expand in front and not be fixed-top.我看到一些类似的帖子说你可以使用添加到导航栏的“固定顶部”类来实现这一点 - 我试过了,它确实有效,但我宁愿没有导航栏固定顶部,并且无法弄清楚如何让它在前面扩展而不是固定顶部。 I'm relatively new to HTML/CSS so apologies if i'm missing something obious here.我对 HTML/CSS 比较陌生,所以如果我在这里遗漏了一些令人讨厌的东西,我深表歉意。 Code is below.代码如下。

<section class="navigation">
    <nav class="navbar navbar-expand-lg navbar-dark">
      <a class="navbar-brand" href="index.html"><img class="home_icon" src="Home_icon.png"></a>
      <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
      </button>
      <div class="collapse navbar-collapse" id="navbarSupportedContent">
        <ul class="navbar-nav mr-auto">
          <li class="nav-item">
            <a class="nav-link" href="shows.html">SHOWS <span class="sr-only">(current)</span></a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="music.html">MUSIC</a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="contact.html">CONTACT</a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="about.html">ABOUT</a>
          </li>
        </ul>
      </div>
      <div class="collapse navbar-collapse" id="navbarSupportedContent">
        <ul class="navbar-nav ml-auto">
          <li class="nav-item">
            <a class="nav-link" href="https://facebook.com/sweetchicle"><i class="fab fa-facebook-f social-icon"></i></a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="https://twitter.com/sweetchicleband"><i class="fab fa-twitter social-icon"></i></a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="https://www.instagram.com/sweetchiclemusic/"><i class="fab fa-instagram social-icon"></i></a>
          </li>
        </ul>
      </div>
    </nav>
  </section>

You could make the position of section absolute and use container-fluid to fill the width of the viewport.您可以将 position 设为绝对截面,并使用 container-fluid 填充视口的宽度。 A z-index will also be needed to make the nav function and appear on top of other content.还需要一个 z-index 来制作导航 function 并出现在其他内容的顶部。 Try applying the following to the opening section tag:尝试将以下内容应用于开头部分标记:

    <section class="navigation position-absolute container-fluid" style="z-index: 1;">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM