无法使居中徽标在折叠时重新定位到右侧

时间:2018-06-27 05:32:57

标签: bootstrap-4 navbar mdbootstrap

我无法让徽标在折叠时停留在导航栏的右上角。查看有问题的图片。

Collapsed content

Navbar before collapse

审核代码:

    <nav class="navbar navbar-expand-md fixed-top navbar-light blue-grey lighten-5 mx-auto">
    <div class="container">

    <!-- Collapse Button -->
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#mobileNav" aria-controls="mobileNav" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
    </button>

    <!-- Collapsible Content -->
    <div class="collapse navbar-collapse justify-content-md-center font-weight-bold" id="mobileNav">

        <!-- Links Left -->
        <ul class="navbar-nav">
            <li class="nav-item">
                <a class="nav-link" href="#">Internet</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="#">Building Managers</a>
            </li>
        </ul>

        <!-- Navbar Brand -->
        <a id="logo" class="navbar-brand" href="index.html">
            <img class="hidden-sm-down" src="img/logoNav.png" alt="Lone Star Fiber"> 
        </a>

        <!-- Links Right -->
        <ul class="navbar-nav">
            <li class="nav-item">
                <a class="nav-link" href="#">Business Internet</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="#">Developers</a>
            </li>
        </ul>
    </div>
</nav>

2 个答案:

答案 0 :(得分:0)

使用d-none d-md-block隐藏sm屏幕尺寸的图像,并使用d-md-none d-sm-block显示图像在sm屏幕尺寸上不会塌陷。

请参阅小提琴:https://jsfiddle.net/khz5uv1r/25/

img{
  height:50px;
  width:50px;
}
  <nav class="navbar navbar-expand-md fixed-top navbar-light blue-grey lighten-5 mx-auto">
    <div class="container">

    <!-- Collapse Button -->
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#mobileNav" aria-controls="mobileNav" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
    </button>

    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
  <!-- Collapsible Content -->

          <div class="pic d-md-none d-sm-block">
        <a id="logo"  href="index.html">
            <img src="https://material.angular.io/assets/img/examples/shiba1.jpg" alt="Lone Star Fiber"> 
        </a>
        </div>
    <nav class="collapse navbar-collapse justify-content-md-center font-weight-bold" id="mobileNav">
        <ul class="navbar-nav">
            <li class="nav-item">
                <a class="nav-link" href="#">Internet</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="#">Building Managers</a>
            </li>
        <li class="nav-item pic d-none d-md-block">
        <a id="logo"  href="index.html">
            <img src="https://material.angular.io/assets/img/examples/shiba1.jpg" alt="Lone Star Fiber"> 
        </a>
        </li>
            <li class="nav-item">
                <a class="nav-link" href="#">Business Internet</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="#">Developers</a>
            </li>
        </ul>
    </div>
    </div>
</nav>

答案 1 :(得分:0)

我认为该方法应类似于:Bootstrap NavBar with left, center or right aligned items

使用2个单独的nav-collapse和相同的.mobile-nav目标。使用order-*类在右侧的移动菜单之前显示徽标...

<nav class="navbar navbar-expand-md fixed-top navbar-light blue-grey lighten-5 mx-auto">
    <div class="container">

        <!-- Collapse Button -->
        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target=".mobile-nav" aria-controls="mobileNav" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>

        <!-- Collapsible Content -->
        <div class="collapse navbar-collapse justify-content-md-center font-weight-bold mobile-nav order-2">

            <!-- Links Left -->
            <ul class="navbar-nav">
                <li class="nav-item">
                    <a class="nav-link" href="#">Internet</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="#">Building Managers</a>
                </li>
            </ul>
            </div>
            <!-- Navbar Brand -->
            <a id="logo" class="navbar-brand order-1 order-md-2 text-center" href="index.html">
                <img class="" src="//placehold.it/130x30?text=Lone Star Fiber" alt="Lone Star Fiber">
            </a>
            <div class="collapse navbar-collapse justify-content-md-center font-weight-bold mobile-nav order-2">

            <!-- Links Right -->
            <ul class="navbar-nav">
                <li class="nav-item">
                    <a class="nav-link" href="#">Business Internet</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="#">Developers</a>
                </li>
            </ul>
        </div>
    </div>
</nav>

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