如何在Bootstrap 4 Beta导航栏中使元素居中?

时间:2018-06-20 04:00:58

标签: html css bootstrap-4

我想将 导航栏品牌 放在大屏幕上。 我不明白我在做什么错,我该怎么办? 。请帮忙! 我想要这样的东西:https://www.codeply.com/go/6P65Rawdw4/bootstrap-4-navbar-center-links-examples

<nav class="navbar fixed-top navbar-expand-sm navbar-light " id="MyNavControl">
        <a class="navbar-brand mx-auto" href="#home">BRAND BRAND</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 active" href="#home">Home</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="#AboutSection">About</a>
                </li>
            </ul>

            <form class="ml-auto">
                <input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
            </form>
        </div>  
    </nav>

1 个答案:

答案 0 :(得分:0)

评论后更新 试试这个

<nav class="navbar fixed-top navbar-expand-sm navbar-light " id="MyNavControl">
        <a class="navbar-brand mx-auto" href="#home">BRAND BRAND</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 mx-auto">
                <li class="nav-item">
                    <a class="nav-link active" href="#home">Home</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="#AboutSection">About</a>
                </li>
            </ul>
        </div>  
        <form class="ml-auto">
                <input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
            </form>
    </nav>

<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css">

<nav class="navbar fixed-top navbar-expand-sm navbar-light " id="MyNavControl">
        <a class="navbar-brand mx-auto" href="#home">BRAND BRAND</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 mx-auto">
                <li class="nav-item">
                    <a class="nav-link active" href="#home">Home</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="#AboutSection">About</a>
                </li>
            </ul>
        </div>  
        <form class="ml-auto">
                <input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
            </form>
    </nav>