移动设备上未显示导航栏

2022-07-03 00:00:00 html css navbar bootstrap-5 responsive
    <!-- Navbar -->
    <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
        
        <div class="container-fluid">
            <div class="collapse navbar-collapse" id="navbarNav">
                <ul class="navbar-nav">
                    <li class="nav-item">
                        <a class="nav-link active" aria-current="page" href="index.html">Home</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="`enter code here`">Resume</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="">Linkedin</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="">GitHub</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="">Email</a>
                    </li>
                </ul>
            </div>
        </div>
    </nav>

这是用bootstrap制作的html格式的导航栏。但不知何故,它并没有显示在手机上,有什么建议可以改变这一点吗?我试了很多,我也看了前面的问题,但都没有用


解决方案

如Bootstrap 5 docs...

导航栏可以使用.navbar-toggler、.navbar-坍塌和 .navbar-展开{-sm|-md|-lg|-xl|-xxl}类以确定其 内容折叠在按钮后面&Quot;

您的代码缺少切换器...

<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
    <div class="container-fluid">
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarTogglerDemo01" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarNav">
            <ul class="navbar-nav">
                <li class="nav-item">
                    <a class="nav-link active" aria-current="page" href="index.html">Home</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="`enter code here`">Resume</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="">Linkedin</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="">GitHub</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="">Email</a>
                </li>
            </ul>
        </div>
    </div>
</nav>

Demo


还请注意data attributes have changed in Bootstrap 5

相关文章