Bootstrap 4导航栏在小屏幕尺寸上无法正常工作

时间:2019-02-06 14:57:52

标签: html css twitter-bootstrap bootstrap-4 navbar

我目前正在尝试实现一个导航栏,该导航栏可以在较小的屏幕尺寸下将导航栏选择转换为下拉菜单(如文档显示here。但是,用于切换导航栏显示的按钮未显示) 。它以html格式呈现,但是按钮为空,并且单击负责折叠导航栏的按钮时,不显示任何内容(没有下拉选项,其中id期望有“ home”链接和“ login / regiser”按钮)

导航栏标记:

<nav class="navbar navbar-expand-lg primary">
        <a class="navbar-brand" href="/">Blazor Finances</a>
        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div id="navbarNavDropdown" class="navbar-collapse collapse">
            <ul class="navbar-nav mr-auto">
                <li class="nav-item active">
                    <a class="nav-link" href="/">Home <span class="sr-only">(current)</span></a>
                </li>
            </ul>
            <ul class="navbar-nav">
                <li class="nav-item">
                    <a id="login-register-btn" class="btn btn-primary primary" href="/login">Login/Register</a>
                </li>
            </ul>
        </div>
    </nav>

在大屏幕尺寸下工作正常,但在小型设备上看起来如下: enter image description here

和显示了导航栏切换按钮的屏幕截图已呈现,但似乎没有显示并且无法使用: enter image description here

1 个答案:

答案 0 :(得分:4)

在您的navbar-light中添加navbar-darknavbar(用于深色背景)-这些类负责添加汉堡包。参见下面的演示:

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" />
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.1/css/all.css" />
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js"></script>

<nav class="navbar navbar-light navbar-expand-lg primary">
        <a class="navbar-brand" href="/">Blazor Finances</a>
        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div id="navbarNavDropdown" class="navbar-collapse collapse">
            <ul class="navbar-nav mr-auto">
                <li class="nav-item active">
                    <a class="nav-link" href="/">Home <span class="sr-only">(current)</span></a>
                </li>
            </ul>
            <ul class="navbar-nav">
                <li class="nav-item">
                    <a id="login-register-btn" class="btn btn-primary primary" href="/login">Login/Register</a>
                </li>
            </ul>
        </div>
    </nav>