2017-03-31 169 views
0

我在自舉菜單中有惱人的問題,當我在菜單中添加「navbar窗體」時,菜單的寬度變得大於移動模式下的屏幕寬度(例如,當我減小瀏覽器寬度時,或當我打開手機上的頁面)。只要我刪除表單代碼就知道這個問題會消失。 見我的代碼:Bootstrap導航欄寬度問題

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/> 
 
<li> 
 
      <form class="navbar-form" role="search" action="ActionPages\index_Search_Action.php" method="post" accept-charset="utf-8"> 
 
     <div class="input-group"> 
 
        <div class="input-group-addon" id="basic-addon1"><span class="glyphicon glyphicon-search" style="font-size:large"></span></div> 
 
        <input type="text" name="txtSearch" class="form-control" placeholder="Search" aria-describedby="basic-addon1"> 
 
        </div> 
 
     </form> 
 
     </li>

我應該怎麼辦?

+0

有你試圖給予100%寬度或col-sm-12類的形式 –

+0

@Ryad使用100%寬度幫助小。除非我改變內容的方向(方向:rtl) –

回答

0

也許嘗試刪除您的<li>標籤。這些標籤旨在用於某種列表中。

+0

否則這個問題消失了,這不起作用。無論如何,謝謝 –

1

我們需要看到的DOM爲您用來充分認識這一問題的導航欄的休息,但你可以試試這個,它應該工作:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> 
 

 

 
<!-- Latest compiled and minified JavaScript --> 
 
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script> 
 

 
<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> 
 
    </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> 
 
      <form class="navbar-form" role="search" action="ActionPages\index_Search_Action.php" method="post" accept-charset="utf-8"> 
 
      <div class="input-group"> 
 
       <div class="input-group-addon" id="basic-addon1"><span class="glyphicon glyphicon-search" style="font-size:large"></span></div> 
 
       <input type="text" name="txtSearch" class="form-control" placeholder="Search" aria-describedby="basic-addon1"> 
 
      </div> 
 
      </form> 
 
     </li> 
 
     </ul> 
 
    </div> 
 
    <!-- /.navbar-collapse --> 
 
    </div> 
 
    <!-- /.container-fluid --> 
 
</nav>

+0

使用這將意味着我應該改變大部分設計。無論如何,我會在稍後測試,非常感謝你。 –

+0

如果你不想要一個完整的導航欄,那會崩潰,你可以從代碼片段中刪除大部分不需要的元素。試試這個:[jsFiddle](http://jsfiddle.net/DTcHh/31356/) – Waqas