Bootstrap 4:拆分Navbar,并在两个导航栏切换器中显示,用于小屏幕设备

时间:2019-03-17 07:55:46

标签: bootstrap-4

我使用引导程序4创建了一个导航栏。该导航栏有10个“导航项”。对于大屏幕,它以行显示;对于小屏幕,我使用“ navbar-toggler”。这很好。但我想拆分此导航栏,并在2个导航栏切换器中显示以用于小屏幕。

有可能吗?我也是新手!!

下面是代码:

<nav class="navbar navbar-expand-md my-navbar">
<!-- Brand -->
<a class="navbar-brand"></a>    
<!-- Toggler/collapsibe Button -->
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#collapsibleNavbar">
    <span class="navbar-toggler-icon"></span>
</button>   
<!--Navbar Links -->
<div class="collapse navbar-collapse justify-content-center" id="collapsibleNavbar">
    <ul class="navbar-nav">

        <li class="nav-item">
            <a class="nav-link animated zoomIn" href="#">Link 1</a>
        </li>
        <li class="nav-item">
            <a class="nav-link animated zoomIn" href="#">Link 2</a>
        </li>
        <li class="nav-item">
            <a class="nav-link animated zoomIn" href="#">Link A</a>
        </li>
        <li class="nav-item">
            <a class="nav-link animated zoomIn" href="#">Link B</a>
        </li>
    </ul>
</div>
</nav>

对于小型设备, 我希望链接1和链接2在toggler-1下折叠 和链接A和链接B将合拢切换器2

1 个答案:

答案 0 :(得分:0)

这也许是您的初衷吗?

<nav class="navbar navbar-expand-md my-navbar">
<!-- Brand -->
<a class="navbar-brand"></a>    
<!-- Toggler/collapsibe Button -->
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#collapsibleNavbar1">
    <span class="navbar-toggler-icon"></span>
</button>   
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#collapsibleNavbar2">
    <span class="navbar-toggler-icon"></span>
</button>   
<!--Navbar Links -->
<div class="collapse navbar-collapse justify-content-center" id="collapsibleNavbar1">
    <ul class="navbar-nav">
        <li class="nav-item">
            <a class="nav-link animated zoomIn" href="#">Link 1</a>
        </li>
        <li class="nav-item">
            <a class="nav-link animated zoomIn" href="#">Link 2</a>
        </li>
    </ul>
</div>
<div class="collapse navbar-collapse justify-content-center" id="collapsibleNavbar2">
    <ul class="navbar-nav">
        <li class="nav-item">
            <a class="nav-link animated zoomIn" href="#">Link A</a>
        </li>
        <li class="nav-item">
            <a class="nav-link animated zoomIn" href="#">Link B</a>
        </li>
    </ul>
</div>
</nav>

我们现在有两个可折叠的导航栏#collapsibleNavbar1#collapsibleNavbar2,其中有两个切换器来驱动它们。我发现第一个切换按钮最终出现在菜单栏的中间,但这可能是可样式化的。