2017-10-06 63 views
0

這是代碼。我需要將導航欄(沒有徽標)移動到右側。Bootstrap 4 float-right不能使用導航欄

所以我加了float-right像<div class="collapse navbar-collapse float-right" id="navbarSupportedContent">

但它沒有奏效。

全碼

<nav class="navbar navbar-expand-lg navbar-dark bg-dark"> 
     <a class="navbar-brand" href="#">Popular Quotes Collection</a> 
     <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation"> 
     <span class="navbar-toggler-icon"></span> 
     </button> 

     <div class="collapse navbar-collapse float-right" id="navbarSupportedContent"> 
     <ul class="navbar-nav mr-auto"> 
      <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="#">Submit a Quote</a> 
      </li> 
     </ul> 
     </div> 
    </nav> 

回答

0

你實際上並不需要應用float-right在所有的,而是navbar-toggler-right

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous"> 
 

 
<nav class="navbar navbar-expand-lg navbar-dark bg-dark"> 
 
    <a class="navbar-brand" href="#">Popular Quotes Collection</a> 
 
    <button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation"> 
 
    <span class="navbar-toggler-icon">Toggle</span> 
 
    </button> 
 
    <div class="collapse navbar-collapse" id="navbarSupportedContent"> 
 
    <ul class="navbar-nav mr-auto"> 
 
     <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="#">Submit a Quote</a> 
 
     </li> 
 
    </ul> 
 
    </div> 
 
</nav>

希望這有助於! :)

+0

感謝您的回答。但它不起作用,因爲徽標也在右側。 Logo應該在左側,其他的munu應該在右側 – Sasa1234

+0

因此,可摺疊的下拉菜單應該是唯一的右側? –

+0

就像這樣。請看截圖。 https://image.ibb.co/hpVcdw/32323222222.png – Sasa1234

2

只需添加:

  • .justify-content-end.navbar-collapse

  • 刪除浮動,引導4 Flexbox的默認,所以你可以利用這一點。

像這樣:

<div class="collapse navbar-collapse justify-content-end" id="navbarSupportedContent"> 

Working Resizable Fiddle

enter image description here