如何修复BS4导航栏折叠按钮?

时间:2019-01-16 10:20:40

标签: bootstrap-4

我似乎无法使代码的切换按钮正常工作。调整窗口大小时,它不会显示,随后导航栏也将不起作用。

<nav class="navbar navbar-expand-md bg-faded my-auto mx-0 p-0">
    <a href="/" class="navbar-brand col-md-2 m-0 p-0 text-center app-logo">
        <div class="d-sm-block d-lg-none"><strong>mAn</strong></div>
        <div class="d-none d-sm-none d-lg-block">my App name</div>
    </a>
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#collapsingNavbar3">
        <span class="navbar-toggler-icon"></span>
    </button>
    <div class="navbar-collapse collapse col-md-10 m-0 p-0" id="collapsingNavbar3">
        <ul class="navbar-nav mr-auto">
            <li class="nav-item active">
                <a class="nav-link active" href="#">Home</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="#">About</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="#">Contact</a>
            </li>
        </ul>
        <ul class="nav navbar-nav right-nav">
            <li class="nav-item ">
                <a class="nav-link" href="#" id="displayName">UserName</a>
            </li>
            <li class="nav-item ">
                <a id="btnBack" class="nav-link" style="" href="/logout">logout</a>
            </li>
        </ul>
    </div>
</nav>

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css">

<nav class="navbar navbar-expand-md bg-faded my-auto mx-0 p-0">
    <a href="/" class="navbar-brand col-md-2 m-0 p-0 text-center app-logo">
        <div class="d-sm-block d-lg-none"><strong>mAn</strong></div>
        <div class="d-none d-sm-none d-lg-block">my App name</div>
    </a>
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#collapsingNavbar3">
        <span class="navbar-toggler-icon"></span>
    </button>
    <div class="navbar-collapse collapse col-md-10 m-0 p-0" id="collapsingNavbar3">
        <ul class="navbar-nav mr-auto">
            <li class="nav-item active">
                <a class="nav-link active" href="#">Home</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="#">About</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="#">Contact</a>
            </li>
        </ul>
        <ul class="nav navbar-nav right-nav">
            <li class="nav-item ">
                <a class="nav-link" href="#" id="displayName">UserName</a>
            </li>
            <li class="nav-item ">
                <a id="btnBack" class="nav-link" style="" href="/logout">logout</a>
            </li>
        </ul>
    </div>
</nav>

<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js"></script>

2 个答案:

答案 0 :(得分:0)

正确使用所有链接尝试此操作... 我修改了您的<nav/>类,而不是我使用bg-faded的{​​{1}}

bg-dark navbar-dark

答案 1 :(得分:0)

您可以使用默认类别的Bs4 navbar-dark和bg-dark 获得深色或更多颜色,请访问此link

我只是将bg-faded更改为navbar-dark,将白色字体更改为bg-dark,将深色背景更改为

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css">

<nav class="navbar navbar-expand-md navbar-dark bg-dark my-auto mx-0 p-0">
    <a href="/" class="navbar-brand col-md-2 m-0 p-0 text-center app-logo">
        <div class="d-sm-block d-lg-none"><strong>mAn</strong></div>
        <div class="d-none d-sm-none d-lg-block">my App name</div>
    </a>
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#collapsingNavbar3">
        <span class="navbar-toggler-icon"></span>
    </button>
    <div class="navbar-collapse collapse col-md-10 m-0 p-0" id="collapsingNavbar3">
        <ul class="navbar-nav mr-auto">
            <li class="nav-item active">
                <a class="nav-link active" href="#">Home</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="#">About</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="#">Contact</a>
            </li>
        </ul>
        <ul class="nav navbar-nav right-nav">
            <li class="nav-item ">
                <a class="nav-link" href="#" id="displayName">UserName</a>
            </li>
            <li class="nav-item ">
                <a id="btnBack" class="nav-link" style="" href="/logout">logout</a>
            </li>
        </ul>
    </div>
</nav>

<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js"></script>