保持下拉菜单(语言选择器)始终显示在Bootstrap 4中导航的右侧

时间:2018-04-29 14:26:53

标签: twitter-bootstrap bootstrap-4 navbar

我想在汉堡包按钮前放下一个下拉菜单。挑战在于即使导航栏崩溃也能在同一个地方看到它。 即使我将它置于折叠导航栏崩溃div之外,它总是会与其他导航元素一起崩溃。 有没有比位置更好的解决方案:绝对? < nav class =" navbar navbar-expand-lg navbar-light fixed-top" ID ="导航栏">     < a class =" navbar-brand" HREF ="#">         < img src ="#" ALT ="" ID ="标志">     < / A>     < button class =" navbar-toggler汉堡包汉堡包 - 滑块"类型="按钮"数据肘节="崩"数据目标="#navbarSupportedContent" ID =" toggleNav"> < span class =" hamburger-box"> < span class =" hamburger-inner" >< /跨度> < /跨度>     < /按钮>     < div class =" language-picker">         < ul class =" navbar-nav ml-auto">                   < li class =" nav-item下拉">                 < a class =" nav-link下拉切换" HREF =#&34;的index.html" ID =" navbarDropdown"角色="按钮"数据肘节="下拉"咏叹调-haspopup ="真"咏叹调膨胀="假">语言                 < / A>                 < div class =" dropdown-menu"咏叹调-labelledby =" navbarDropdown">                     < a class =" dropdown-item" HREF ="#">英语< / A>                     < a class =" dropdown-item" HREF ="#">法语< / A>                     <! - < div class =" dropdown-divider">< / div>               < a class =" dropdown-item" href ="#">最佳解决方案< / a> - >             < / DIV>             < /锂>         < / UL>     < / DIV>     < div class =" collapse navbar-collapse" ID =" navbarSupportedContent">         < ul class =" navbar-nav mx-auto">             < li class =" nav-item">                 < a class =" nav-link" HREF ="#"><跨度>联络与LT; /跨度>< / A>             < /锂>             < li class =" nav-item">                 < a class =" nav-link" HREF ="#"><跨度> LOGIN< /跨度>< / A>             < /锂>             < li class =" nav-item">                 < a class =" nav-link chatIcon" href ="#">< img src =" img / icons / account_icon.png" alt ="聊天图标">< / a>             < /锂>         < / UL>         < / DIV>         <! - end collapse navbar-collapse - > < / NAV>

1 个答案:

答案 0 :(得分:1)

将下拉列表和切换器一起包裹在1 div ...

https://www.codeply.com/go/H19BTH57m4

<nav class="navbar navbar-expand-lg navbar-light fixed-top" id="navbar">
    <a class="navbar-brand" href="#">
        <img src="//placehold.it/30" alt="" id="logo">
    </a>
    <div class="d-flex flex-row">
        <div class="language-picker">
            <ul class="navbar-nav ml-auto">
                <li class="nav-item dropdown">
                    <a class="nav-link dropdown-toggle mr-2" href="index.html" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Language
                </a>
                    <div class="dropdown-menu" aria-labelledby="navbarDropdown">
                        <a class="dropdown-item" href="#">English</a>
                        <a class="dropdown-item" href="#">French</a>
                        <!-- <div class="dropdown-divider"></div>
              <a class="dropdown-item" href="#">THE BEST SOLUTION</a> -->
                    </div>
                </li>
            </ul>
        </div>
        <button class="navbar-toggler hamburger hamburger--slider" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" id="toggleNav">
            <span class="hamburger-box navbar-toggler-icon">
            <span class="hamburger-inner"></span>
            </span>
        </button>
    </div>
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
        <ul class="navbar-nav mx-auto">
            <li class="nav-item">
                <a class="nav-link" href="#"><span>CONTACT</span></a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="#"><span>LOGIN</span></a>
            </li>
            <li class="nav-item">
                <a class="nav-link chatIcon" href="#"><img src="//placehold.it/30" alt="a chat icon"></a>
            </li>
        </ul>
    </div>
    <!-- end collapse navbar-collapse -->
</nav>

另一种选择是在下拉列表中使用ml-auto,然后将其从navbar-navhttps://www.codeply.com/go/rtmowu5Bl9

中删除