Reputation: 99
In my Bootstrap navbar, I have a logo in the header and then an inline list. On large screens, the logo and list are on the same line. On smaller screens, I want the logo centered on the first line and the list to center on a second line. But, the list keeps going to vertical stacked instead of remaining inline. How can I prevent the inline list from going vertical as the screen shrinks?
Here is a jsfiddle of my current navbar: https://jsfiddle.net/DTcHh/6936/
I need the links on the right to get closer and closer to the logo as the screen shrinks. Then, when there's no more room, I need those links centered on a new line below the logo, which should be centered on the first line.
Desired effect on small screens: https://drive.google.com/file/d/0B08LN9pHRwLuSkRvV3YwYVk5aWs/view?usp=sharing
html:
<body>
<div class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header navbar-logo">
<a href="#"><img src="http://placehold.it/140x75" class="img-responsive navlogo" alt="logo here"></a>
</div>
<div class="navbar-links">
<ul class="list-inline nav navbar-nav navbar-right navbar-list">
<li><a href="#" style="color: black; font-weight: bold;">FAQ</a></li>
<li><a href="#" style="color: black; font-weight: bold;">Contact</a></li>
<li><a href="#" style="color: black; font-weight: bold">Policies</a></li>
<li><a href="#" style="background-color: #9e1d2a; color: white">For Users</a></li>
<li style="padding-top: 0px; padding-left: 15px"><a data-toggle="collapse" href="#nav-search-collapse"><i class="glyphicon glyphicon-search"></i></a></li>
</ul>
</div>
</div>
<div class="collapse" id="nav-search-collapse">
<ul class="list-inline navbar-list-form">
<li><form class="navbar-form" role="form" method="get" action="#">
<div class="input-group">
<input type="Search" placeholder="Search Data" class="form-control" name="q">
<div class="input-group-btn">
<button class="btn btn-primary">
<span class="glyphicon glyphicon-search"></span>
</button>
</div>
</div>
</form></li>
<li><form class="navbar-form" role="form" method="get" action="#">
<div class="input-group">
<span class="input-group-addon">wwww.</span>
<input type="Search" class="form-control" name="w_searched">
<div class="input-group-btn">
<button class="btn btn-primary">
<span>Search</span>
</button>
</div>
</div>
</form></li>
</ul>
</div>
</div>
</body>
css:
.navbar-list {
padding-top: 5px;
}
.navbar-list li{
font-size: 16px;
}
#nav-search-collapse {
width:100%;
margin: 0 auto;
text-align:center;
}
.navbar-list-form {
display:inline-block;
padding: 0;
}
@media (min-width: 0px) and (max-width: 1000px) {
.navbar-header{
float: left;
width: 100%;
}
.navbar-links {
float: left;
width: 100%;
}
}
Upvotes: 3
Views: 6581
Reputation: 3599
Adding this to your CSS will give you what you are looking for (you are required to define minimum width up-till which all links appear on same newline, it's your decision)
@media (max-width: 1000px) and (min-width: 0px) {
.navbar-links {
text-align: center;
}
.nav>li {
display: inline;
}
.nav>li>a {
display: inline;
}
}
Upvotes: 2
Reputation: 2478
https://jsfiddle.net/DTcHh/6940/
I have added this code:
.navbar-logo, .navbar-links {
display: inline;
width: initial !important;
}
If you have any questions about the modifications let me know.
Upvotes: 1