2016-08-04 242 views
0

我試圖設計一個Bootstrap 4導航欄,它保留了導航欄品牌,而不會在摺疊時消失。Bootstrap 4摺疊導航欄失去導航欄品牌

這裏是我的代碼:

<nav class="navbar navbar-light bg-faded"> 
    <button class="navbar-toggler hidden-sm-up" type="button" data-toggle="collapse" data-target="#exCollapsingNavbar2" aria-controls="exCollapsingNavbar2" aria-expanded="false" aria-label="Toggle navigation"> 
    &#9776; 
    </button> 
    <div class="collapse navbar-toggleable-xs" id="exCollapsingNavbar2"> 
    <a class="navbar-brand" href="#">Responsive navbar</a> 
    <ul class="nav navbar-nav"> 
     <li class="nav-item active"> 
     <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a> 
     </li> 
     <li class="nav-item"> 
     <a class="nav-link" href="#">Features</a> 
     </li> 
     <li class="nav-item"> 
     <a class="nav-link" href="#">Pricing</a> 
     </li> 
     <li class="nav-item"> 
     <a class="nav-link" href="#">About</a> 
     </li> 
    </ul> 
    </div> 
</nav> 

所以僅僅是明確的,在導航項和Navbar的品牌時,導航欄被倒塌消失了,我想要的導航欄,品牌仍是可見的。

我能想到的唯一的CSS就是使用display,但這沒有任何效果。

感謝您的任何建議!

回答

2

你應該改變你的HTML標記,並確保該.nav-brand超出了<div class="collapse navbar-toggleable-xs" id="exCollapsingNavbar2">

<nav class="navbar navbar-light bg-faded"> 
    <button class="navbar-toggler hidden-sm-up" type="button" data-toggle="collapse" data-target="#exCollapsingNavbar2" aria-controls="exCollapsingNavbar2" aria-expanded="false" aria-label="Toggle navigation"> 
    &#9776; 
    </button> 
    <a class="navbar-brand" href="#">Responsive navbar</a> 
    <div class="collapse navbar-toggleable-xs" id="exCollapsingNavbar2"> 
    .... 

現在你的導航欄看起來應該在小視窗,如下圖所示: navbar on small viewports

您可能還想將pull-xs-right類添加到「漢堡包」按鈕:

<button class="navbar-toggler hidden-sm-up pull-xs-right" type="button" data-toggle="collapse" data-target="#exCollapsingNavbar2" aria-controls="exCollapsingNavbar2" aria-expanded="false" aria-label="Toggle navigation"> 

那麼就應該看起來像下圖所示:

enter image description here

當您單擊該按鈕時,第一個鏈接仍然旁邊漂浮到.nav-brand

enter image description here

使用以下SCSS代碼從特殊小視口中刪除float-left.nav-brand

.navbar { 
    @include media-breakpoint-down(xs) { 
    .navbar-brand { 
     float: none; 
    } 
    } 
} 
上述

的SCSS代碼編譯成CSS代碼如下:http://bassjobsen.weblogs.fm/bootstrap-4s-responsive-navbars/

@media (max-width: 543px) { 
    .navbar .navbar-brand { 
    float: none; 
    } 
} 

關於引導4的響應導航欄的更多信息,也可以在發現