twitter-bootstrap – Bootstrap 4 Navbar即使在切换时也保持在右侧

前端之家收集整理的这篇文章主要介绍了twitter-bootstrap – Bootstrap 4 Navbar即使在切换时也保持在右侧前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
即使切换展开,我也会尝试让“登录部分”保持在右上角.我试图浮动该部分,但它没有工作.

这是我的代码

<nav class="navbar navbar-expand-lg bg-dark navbar-dark fixed-top">
        <div class="container">
            <div class="navbar-header">
                <button class="navbar-toggler"
                        type="button"
                        data-toggle="collapse"
                        data-target="#mymenu">
                    <span class="sr-only">toggle navigation</span>
                    <span class="navbar-toggler-icon"></span>
                </button>
                <a href="#" class="navbar-brand">App</a>

            </div>
            <div class="collapse navbar-collapse" id="mymenu"> 
                <!-- nav body -->
                <ul class="nav navbar-nav mr-auto">
                    <li class="active nav-item"><a class="nav-link" href="index.html">Home</a></li>
                    <li class="nav-item"><a class="nav-link" href="#">Item 1</a></li>
                    <li class="nav-item"><a class="nav-link" href="#">Item 2</a></li>
                    <li class="nav-item dropdown">
                        <a  class="nav-link dropdown-toggle"
                           data-toggle="dropdown" role="button"
                           href="#">Item 3
                        </a>
                        <ul class="dropdown-menu">
                            <li><a class="dropdown-item" href="#">Item 3.1</a></li>
                            <li><a class="dropdown-item" href="#">Item 3.2</a></li>
                            <li><a class="dropdown-item" href="#">Item 3.3</a></li>
                        </ul>
                    </li>
                </ul>
                <!-------------------Search---------------------->
                <form class="form-inline my-2 my-lg-0 position-relative">
                    <input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
                    <button class="btn btn-outline-light my-2 my-sm-0" type="submit">Search</button>
                </form>


            </div>
            <!--------------------User---------------------->
            <div class="ml-lg-5">
                <a class="navbar-brand" href="#">Log In</a>
            </div>
        </div>
    </nav>

谢谢你考虑我的要求.

解决方法

您可以使用flexBox ordering classes调整“登录”div的位置.例如,将它放在标记中的导航栏折叠之前,然后使用order-lg-last order-0将其定位在较大屏幕上的最后(第3个),然后在移动导航栏切换时使用较小屏幕中的自然顺序(第2个) .

https://www.codeply.com/go/7Mz5XkMckc

<nav class="navbar navbar-expand-lg bg-dark navbar-dark fixed-top">
    <div class="container">
        <div class="navbar-header">
            <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#mymenu">
                <span class="sr-only">toggle navigation</span>
                <span class="navbar-toggler-icon"></span>
            </button>
            <a href="#" class="navbar-brand">App</a>
        </div>
        <div class="ml-lg-5 order-lg-last order-0">
            <a class="navbar-brand" href="#">Log In</a>
        </div>
        <div class="collapse navbar-collapse" id="mymenu"> 
            <ul class="nav navbar-nav mr-auto">
                <li class="active nav-item"><a class="nav-link" href="index.html">Home</a></li>
                <li class="nav-item"><a class="nav-link" href="#">Item 1</a></li>
                <li class="nav-item"><a class="nav-link" href="#">Item 2</a></li>
                <li class="nav-item dropdown">
                    <a class="nav-link dropdown-toggle" data-toggle="dropdown" role="button" href="#">Item 3
                    </a>
                    <ul class="dropdown-menu">
                        <li><a class="dropdown-item" href="#">Item 3.1</a></li>
                        <li><a class="dropdown-item" href="#">Item 3.2</a></li>
                        <li><a class="dropdown-item" href="#">Item 3.3</a></li>
                    </ul>
                </li>
            </ul>
            <form class="form-inline my-2 my-lg-0 position-relative">
                <input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
                <button class="btn btn-outline-light my-2 my-sm-0" type="submit">Search</button>
            </form>
        </div>
    </div>
</nav>
原文链接:https://www.f2er.com/bootstrap/234000.html

猜你在找的Bootstrap相关文章