2017-07-07 381 views
3

我正在使用CodePen進行項目工作,我正在使用引導來創建導航欄。但由於某種原因,它垂直顯示而不是水平顯示。即使我複製並粘貼W3Schools示例和Bootstrap website中的代碼。我不知道還有什麼要做。請幫忙。Bootstrap導航欄顯示爲垂直而非水平


這是W3Schools的示例代碼:

<nav class="navbar navbar-default"> 
     <div class="container-fluid"> 
     <div class="navbar-header"> 
      <a class="navbar-brand" href="#">WebSiteName</a> 
     </div> 
     <ul class="nav navbar-nav"> 
      <li class="active"><a href="#">Home</a></li> 
      <li><a href="#">Page 1</a></li> 
      <li><a href="#">Page 2</a></li> 
      <li><a href="#">Page 3</a></li> 
     </ul> 
     </div> 


這是從引導網站示例代碼:

<nav class="navbar navbar-default"> 
     <div class="container-fluid"> 
<!-- Brand and toggle get grouped for better mobile display --> 
<div class="navbar-header"> 
    <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false"> 
    <span class="sr-only">Toggle navigation</span> 
    <span class="icon-bar"></span> 
    <span class="icon-bar"></span> 
    <span class="icon-bar"></span> 
    </button> 
    <a class="navbar-brand" href="#">Brand</a> 
</div> 

<!-- Collect the nav links, forms, and other content for toggling --> 
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1"> 
    <ul class="nav navbar-nav"> 
    <li class="active"><a href="#">Link <span class="sr-only">(current)</span></a></li> 
    <li><a href="#">Link</a></li> 
    <li class="dropdown"> 
     <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a> 
     <ul class="dropdown-menu"> 
     <li><a href="#">Action</a></li> 
     <li><a href="#">Another action</a></li> 
     <li><a href="#">Something else here</a></li> 
     <li role="separator" class="divider"></li> 
     <li><a href="#">Separated link</a></li> 
     <li role="separator" class="divider"></li> 
     <li><a href="#">One more separated link</a></li> 
     </ul> 
    </li> 
    </ul> 
    <form class="navbar-form navbar-left"> 
    <div class="form-group"> 
     <input type="text" class="form-control" placeholder="Search"> 
    </div> 
    <button type="submit" class="btn btn-default">Submit</button> 
    </form> 
    <ul class="nav navbar-nav navbar-right"> 
    <li><a href="#">Link</a></li> 
    <li class="dropdown"> 
     <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a> 
     <ul class="dropdown-menu"> 
     <li><a href="#">Action</a></li> 
     <li><a href="#">Another action</a></li> 
     <li><a href="#">Something else here</a></li> 
     <li role="separator" class="divider"></li> 
     <li><a href="#">Separated link</a></li> 
     </ul> 
    </li> 
    </ul> 
</div><!-- /.navbar-collapse --> 


兩者都不起作用。是的,我已經三次檢查了我的<link><script>標籤。

編輯:here is my CodePen

+0

你鏈接到文檔中的引導庫嗎? – Chiller

+0

你能分享一下你的CodePen的鏈接,這樣我們可以看看嗎? – trevorp

+0

檢查您的瀏覽器控制檯,如果可能的話在這裏撥弄 –

回答

2

首先像你正在使用引導3標記的意見,並要鏈接到兩個引導3 4刪除引導4 CSS。然後,你需要有與類的collapse navbar-collapse股利所以只需添加這是有nav就像ID股利如下:

<nav class="navbar navbar-inverse"> 
    <div class="container-fluid"> 

    <div class="navbar-header"> 
     <a class="navbar-brand" href="#about"> 
     <span style="font-family: 'Source Code Pro', Monospace; color:green"><i class="fa fa-code"></i>Ryan</span></a> 
    </div> 
    <div class="collapse navbar-collapse" id="nav"> 
    <ul class="nav navbar-nav"> 
     <li><a href="#about">About</a></li> 
     <li><a href="#portfolio">Portfolio</a></li> 
     <li><a href="#contact">Contact</a></li> 
    </ul> 
    </div> 
    </div> 
</nav> 

您可能要崩潰按鈕添加到導航欄標題爲否則你的鏈接不會顯示在移動寬度,所以它看起來像:

<nav class="navbar navbar-inverse"> 
    <div class="container-fluid"> 
    <div class="navbar-header"> 
     <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#nav" aria-expanded="false"> 
     <span class="sr-only">Toggle navigation</span> 
     <span class="icon-bar"></span> 
     <span class="icon-bar"></span> 
     <span class="icon-bar"></span> 
     </button> 
     <a class="navbar-brand" href="#about"> 
     <span style="font-family: 'Source Code Pro', Monospace; color:green"><i class="fa fa-code"></i>Ryan</span> 
     </a> 
    </div> 
    <div class="collapse navbar-collapse" id="nav"> 
    <ul class="nav navbar-nav"> 
     <li><a href="#about">About</a></li> 
     <li><a href="#portfolio">Portfolio</a></li> 
     <li><a href="#contact">Contact</a></li> 
    </ul> 
    </div> 
    </div> 
</nav> 
0

正如有人說的 - 從加載CSS文件中刪除的自舉4,它會工作