使用Bootstrap 5将链接居中在navbar-brand下方需要帮助。

huangapple go评论53阅读模式
英文:

Need help in centering links below navbar-brand using Bootstrap 5

问题

我正在练习如何使用Bootstrap 5创建一个导航栏,但无法让链接居中并位于navbar-brand下方。

这是我的当前导航栏的截图。

截图

我的代码:

<!-- 导航栏 -->
<nav class="navbar navbar-expand-lg flex-column align-items-stretch" style="background-color: #FAF8F1; border: 3px solid;">
    <div class="d-flex">
        <a class="navbar-brand mx-sm-auto mr-auto" href=""> Honeybee Babies </a>
        <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>
    <div class="collapse navbar-collapse w-100" id="navbarSupportedContent">
        <ul class="navbar-nav justify-content-center">
            <li class="nav-item rounded-pill" style="background-color: #C58940;">
                <a class="nav-link" style="color: #FAF8F1" href="">Baby Essentials</a>
            </li>
            <li class="nav-item rounded-pill" style="background-color: #C58940;">
                <a class="nav-link" style="color: #FAF8F1" href="">Price Range</a>
            </li>
            <li class="nav-item rounded-pill" style="background-color: #C58940;">
                <a class="nav-link" style="color: #FAF8F1" href="">Brands</a>
            </li>
        </ul>
        <form class="d-flex" role="search">
            <input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
            <button class="btn" style="color: #C58940" type="submit">Search</button>
        </form>
    </div>
</nav>

我尝试在<ul class="navbar-nav">中使用justify-content-center,但不确定我做错了什么。

任何帮助/建议将不胜感激。

谢谢!

英文:

I am practicing how to create a navbar using Bootstrap 5 and can't get the links centered and below the navbar-brand.

I've attach an image of my current navbar.

Screenshot

My script:

<!-- Nav Bar -->
<nav class="navbar navbar-expand-lg flex-column align-items-stretch" style="background-color: #FAF8F1; border:3px solid;">
<div class="d-flex">
<a class="navbar-brand mx-sm-auto mr-auto" href=""> Honeybee Babies </a>
<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>
<div class="collapse navbar-collapse w-100" id="navbarSupportedContent">
<unli class="navbar-nav">
<li class="nav-item rounded-pill" style="background-color:#C58940;">
<a class="nav-link" style="color:#FAF8F1" href="">Baby Essentials</a>
</li>
<li class="nav-item rounded-pill" style="background-color:#C58940;">
<a class="nav-link" style="color:#FAF8F1" href="">Price Range</a>
</li>
<li class="nav-item rounded-pill" style="background-color:#C58940;">
<a class="nav-link" style="color:#FAF8F1" href="">Brands</a>
</li>
</unli>
<form class="d-flex" role="search">
<input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
<button class="btn" style="color:#C58940" type="submit">Search</button>
</form>
</div>
</div>
</nav>

I've tried using justify-content-center in <unli class="navbar-nav">

I'm not sure what I'm doing wrong.

Any help/advice would be appreciated.

Thanks!

答案1

得分: 0

justify-content-center添加到navbar-collapse中。

请看下面的代码片段。

<div class="collapse navbar-collapse w-100 justify-content-center" id="navbarSupportedContent">

以上是翻译好的部分,没有其他内容。

英文:

Add justify-content-center to the navbar-collapse.

See the snippet below.

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-html -->

&lt;link href=&quot;https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css&quot; rel=&quot;stylesheet&quot; integrity=&quot;sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD&quot; crossorigin=&quot;anonymous&quot;&gt;
&lt;script src=&quot;https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js&quot; integrity=&quot;sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN&quot; crossorigin=&quot;anonymous&quot;&gt;&lt;/script&gt;
&lt;nav class=&quot;navbar navbar-expand-lg flex-column align-items-stretch&quot; style=&quot;background-color: #FAF8F1; border:3px solid;&quot;&gt;
&lt;div class=&quot;d-flex&quot;&gt;
&lt;a class=&quot;navbar-brand mx-sm-auto mr-auto&quot; href=&quot;&quot;&gt; Honeybee Babies &lt;/a&gt;
&lt;button class=&quot;navbar-toggler&quot; type=&quot;button&quot; data-bs-toggle=&quot;collapse&quot; data-bs-target=&quot;#navbarSupportedContent&quot; aria-controls=&quot;navbarSupportedContent&quot; aria-expanded=&quot;false&quot; aria-label=&quot;Toggle navigation&quot;&gt;
&lt;span class=&quot;navbar-toggler-icon&quot;&gt;&lt;/span&gt;
&lt;/button&gt;
&lt;/div&gt;
&lt;div class=&quot;collapse navbar-collapse w-100 justify-content-center&quot; id=&quot;navbarSupportedContent&quot;&gt;
&lt;unli class=&quot;navbar-nav&quot;&gt;
&lt;li class=&quot;nav-item rounded-pill&quot; style=&quot;background-color:#C58940;&quot;&gt;
&lt;a class=&quot;nav-link&quot; style=&quot;color:#FAF8F1&quot; href=&quot;&quot;&gt;Baby Essentials&lt;/a&gt;
&lt;/li&gt;
&lt;li class=&quot;nav-item rounded-pill&quot; style=&quot;background-color:#C58940;&quot;&gt;
&lt;a class=&quot;nav-link&quot; style=&quot;color:#FAF8F1&quot; href=&quot;&quot;&gt;Price Range&lt;/a&gt;
&lt;/li&gt;
&lt;li class=&quot;nav-item rounded-pill&quot; style=&quot;background-color:#C58940;&quot;&gt;
&lt;a class=&quot;nav-link&quot; style=&quot;color:#FAF8F1&quot; href=&quot;&quot;&gt;Brands&lt;/a&gt;
&lt;/li&gt;
&lt;/unli&gt;
&lt;form class=&quot;d-flex&quot; role=&quot;search&quot;&gt;
&lt;input class=&quot;form-control me-2&quot; type=&quot;search&quot; placeholder=&quot;Search&quot; aria-label=&quot;Search&quot;&gt;
&lt;button class=&quot;btn&quot; style=&quot;color:#C58940&quot; type=&quot;submit&quot;&gt;Search&lt;/button&gt;
&lt;/form&gt;
&lt;/div&gt;
&lt;/nav&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年2月6日 05:36:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/75355698.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定