使用弯曲方向时删除空间:导航栏中的列- bootstrap 5

vc6uscn9  于 2023-05-27  发布在  Bootstrap
关注(0)|答案(1)|浏览(206)

我正在使用基本的导航栏:(第一个例子在他们的网站)我也使用灵活的方向设置为“列”,以显示图像以上的菜单项。
https://getbootstrap.com/docs/5.0/components/navbar/
我有一个标志,我想与链接的权利下面的地方。然而,在图像和链接之间有一个空白的空间:(下方红色部分为波浪线)

我的问题是,我如何摆脱这种空间,使图像和菜单项之间没有空间?另外,什么是正确的引导代码,使菜单项拉伸到与图像相同的精确宽度?我在下面提供了一个完整的样本。要重新创建问题,请“运行代码段”并选择“整页”。谢谢你!

#mynavbar{
  border: 2px solid black;
}

#mynavbarinside{
  border: 2px solid black;
}
<html>
  <head>
    <meta charset="utf-8">
    <title>Bootstrap demo</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">
  </head>
<body>
<nav id="mynavbar" class="navbar navbar-expand-lg navbar-light bg-light">
                <div class="container-fluid" style="flex-direction: column;">
                    <div class="navbar-brand">
                        <img src="https://shapedplugin.com/wp-content/uploads/2023/04/Create-a-full-width-ticker-logo-carousel.png" class="img-fluid">
                    </div>
                    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
                        <span class="navbar-toggler-icon"></span>
                    </button>
                    <div id="mynavbarinside" class="collapse navbar-collapse" id="navbarSupportedContent">
                        <ul id="site_nav" class="navbar-nav mx-auto">
                            <li class="nav-item" style="width: 20%">
                                <a class="nav-link" href="http://link01" target="_blank">
                                    Link<br>
                                    One
                                </a>
                            </li>
                            <li class="nav-item" style="width: 20%">
                                <a class="nav-link" href="http://link02" target="_blank">
                                    Link<br>
                                    Two
                                </a>
                            </li>
                            <li class="nav-item" style="width: 20%">
                                <a class="nav-link" href="http://link03" target="_blank">
                                    Link<br>
                                    Three
                                </a>
                            </li>
                            <li class="nav-item" style="width: 20%">
                                <a class="nav-link" href="http://link04" target="_blank">
                                    Link<br>
                                    Four
                                </a>
                            </li>
                            <li class="nav-item" style="width: 20%">
                                <a class="nav-link" href="http://link05" target="_blank">
                                    Link<br>
                                    Five
                                </a>
                            </li>
                            
                        </ul>
                    </div>
                </div>
            </nav>
            
            <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-kenU1KFdBIe4zVF0s0G1M5b4hcpxyD9F7jL+jjXkk+Q2h455rYXK/7HAuoJl+0I4" crossorigin="anonymous"></script>
            
</body>
</html>
lmyy7pcs

lmyy7pcs1#

这是由于navbar-brand默认设置了padding-bottom。要删除它,请将Bootstrap类pb-0添加到navbar-brand
请参见下面的片段。

#mynavbar {
  border: 2px solid black;
}

#mynavbarinside {
  border: 2px solid black;
}
<html>
   <head>
      <meta charset="utf-8">
      <title>Bootstrap demo</title>
      <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">
   </head>
   <body>
      <nav id="mynavbar" class="navbar navbar-expand-lg navbar-light bg-light">
         <div class="container-fluid" style="flex-direction: column;">
            <div class="navbar-brand pb-0">
               <img src="https://shapedplugin.com/wp-content/uploads/2023/04/Create-a-full-width-ticker-logo-carousel.png" class="img-fluid">
            </div>
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
            </button>
            <div id="mynavbarinside" class="collapse navbar-collapse" id="navbarSupportedContent">
               <ul id="site_nav" class="navbar-nav mx-auto">
                  <li class="nav-item" style="width: 20%">
                     <a class="nav-link" href="http://link01" target="_blank">
                     Link<br>
                     One
                     </a>
                  </li>
                  <li class="nav-item" style="width: 20%">
                     <a class="nav-link" href="http://link02" target="_blank">
                     Link<br>
                     Two
                     </a>
                  </li>
                  <li class="nav-item" style="width: 20%">
                     <a class="nav-link" href="http://link03" target="_blank">
                     Link<br>
                     Three
                     </a>
                  </li>
                  <li class="nav-item" style="width: 20%">
                     <a class="nav-link" href="http://link04" target="_blank">
                     Link<br>
                     Four
                     </a>
                  </li>
                  <li class="nav-item" style="width: 20%">
                     <a class="nav-link" href="http://link05" target="_blank">
                     Link<br>
                     Five
                     </a>
                  </li>
               </ul>
            </div>
         </div>
      </nav>
      <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-kenU1KFdBIe4zVF0s0G1M5b4hcpxyD9F7jL+jjXkk+Q2h455rYXK/7HAuoJl+0I4" crossorigin="anonymous"></script>
   </body>
</html>

相关问题