I am migrating from the Twitter Bootstrap version 2.3.2 to the latest version 3 RC 1. Now I meet one problem with the search buttons in the top navigation bar. HTML code is below:
<body>
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<a class="navbar-brand" href="#">Brand</a>
<div class="nav-collapse collapse">
<ul class="nav navbar-nav">
<li><a href="#">Nav Item 1</a></li>
<li class="active"><a href="#">Nav Item 2</a></li>
<li><a href="#">Nav Item 3</a></li>
<li><a href="#">Nav Item 4</a></li>
</ul>
<form class="navbar-form pull-right">
<div class="input-group">
<input type="search" class="form-control" placeholder="Search"/>
<span class="input-group-btn">
<button type="submit" class="btn btn-default">Search</button>
</span>
</div>
</form>
</div>
</div>
</div>
</body>
The problem is, it works perfectly in Firefox, but in Chrome or IE 9 it makes the search box super long and thus moves this search box and button below the navigation bar.
I tried troubleshooting and found if I removed "pull-right" from the form, the search box and button will be moved above inline with the navigation items, but lost the effect that pull-right brought - it would occupy all line space on the right.
Moreover as debugging if i replaced the search form with
<form class="navbar-form pull-right">
<div class="input-group">
<input type="text" placeholder="Search">
<button type="submit" class="btn btn-default">Search</button>
</div>
</form>
Then it will simply work well; but it's not my purpose either.
Any issue with my code? Or is it a problem with the version 3 RC 1? Anyway to address it?
You can add the col-sm-4
class to your <form>
element.
This should keep them the correct width depending on the screen width.
Play with the column sizing (col-sm-**) until you get it the way you want it.
See this jsFiddle demo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With