简体   繁体   English

bootstrap 4 导航栏在左侧和右侧有填充

[英]bootstrap 4 navbar has padding on left and right side

I'm not sure what I'm missing here, I know I can add the CSS to take away the padding from the parent div but I thought that bootstrap would make the navbar the full width of the page?我不确定我在这里缺少什么,我知道我可以添加 CSS 以从父 div 中删除填充,但我认为引导程序会使导航栏成为页面的全宽? Here's my code:这是我的代码:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>Contact</title>
    <!--Bootstrap CSS-->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
    <link rel="stylesheet" type="text/css" media="screen" href="main.css" />
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  </head>

  <body>
    <div class="container-fluid" id="outer">
    <header>
      <nav class="navbar navbar-expand-lg navbar-light bg-secondary">
        <a class="navbar-brand" href="#">
          <img src="\movieTheater.jpg" width="10%" height="10%" alt="">
          Movie Theater
        </a>
        <div class="collapse navbar-collapse" id="navbarNav">
          <ul class="navbar-nav ml-auto">
            <li class="nav-item active">
              <a class="nav-link" href="home.html">Home</a>
            </li>
            <li class="nav-item">
              <a class="nav-link" href="about.html">About</a>
            </li>
            <li class="nav-item">
              <a class="nav-link" href="contact.html">Contact</a>
            </li>
          </ul>
        </div>
      </nav>
    </header>
    </div>
  </body>

</html>

The container-fluid class is 100% wide, but it has some padding applied.容器流体类是 100% 宽的,但它应用了一些填充。 To manage the padding you can use p-* classes from Bootstrap 4 (read the spacing section from the documentation).要管理填充,您可以使用Bootstrap 4 中的p-*类(阅读文档中的间距部分)。 In your particular case, you need the p-0 class to remove the padding.在您的特定情况下,您需要p-0类来删除填充。 As an extra, I have added the collpase menu button, if you don't include it your navbar will not work correctly when collapsed.另外,我添加了折叠菜单按钮,如果您不包含它,您的navbar在折叠时将无法正常工作。 Check the next example:检查下一个示例:

 <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous"> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script> <div class="container-fluid p-0" id="outer"> <header> <nav class="navbar navbar-expand-lg navbar-light bg-secondary"> <a class="navbar-brand" href="#"> <img src="\\movieTheater.jpg" width="10%" height="10%" alt=""> Movie Theater </a> <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation"> <span class="navbar-toggler-icon"></span> </button> <div class="collapse navbar-collapse" id="navbarNav"> <ul class="navbar-nav ml-auto"> <li class="nav-item active"> <a class="nav-link" href="home.html">Home</a> </li> <li class="nav-item"> <a class="nav-link" href="about.html">About</a> </li> <li class="nav-item"> <a class="nav-link" href="contact.html">Contact</a> </li> </ul> </div> </nav> </header> </div>

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

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