Bootstrap 4在导航栏中居中搜索栏

2w3kk1z5  于 2022-12-07  发布在  Bootstrap
关注(0)|答案(2)|浏览(290)

我尝试将搜索栏居中放置在导航栏中。目前,我将搜索栏左对齐,但我尝试将搜索栏居中放置在导航栏中。这是我的HTML代码:

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" rel="stylesheet" />
<nav class="navbar navbar-expand-lg navbar-light bg-light navbar-custom">
    <a class="navbar-brand" href="#">ICT-Hulp(Waarschijnelijk logo)</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">
                <div class="justify-content-md-center">
                    <form class="form-inline my-2 my-lg-0">
                        <input class="form-control mr-sm-2" type="text" placeholder="Zoeken..." aria-label="Search" style="width: 600px;">
                     
                        <button class="btn btn-info my-2 my-sm-0" type="submit">Search</button>
                    </form>
                </div>
            </li>
        </ul>
    </div>
</nav>

我无法让搜索栏居中。我也无法在 Bootstrap 网站上找到它,因为它非常模糊

txu3uszq

txu3uszq1#

ml-auto类与mr-auto沿着添加到navbar-nav

mwecs4sa

mwecs4sa2#

您可以添加margin-left:auto方法是将 mr-auto 添加到 navbar,使搜索栏在导航栏中居中。但是它不会位于标题的中心,因为在导航栏旁边还有另一个组件。

<ul class="navbar-nav mr-auto ml-auto">
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" rel="stylesheet" />
<nav class="navbar navbar-expand-lg navbar-light bg-light navbar-custom">
    <a class="navbar-brand" href="#">ICT-Hulp(Waarschijnelijk logo)</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 ml-auto">
            <li class="nav-item">
                <div class="justify-content-md-center">
                    <form class="form-inline my-2 my-lg-0 my-lg-0">
                        <input class="form-control mr-sm-2" type="text" placeholder="Zoeken..." aria-label="Search" style="width: 600px;">
                     
                        <button class="btn btn-info my-2 my-sm-0" type="submit">Search</button>
                    </form>
                </div>
            </li>
        </ul>
    </div>
</nav>

相关问题