I put navbar outside the container to make the nabar get the full width. But strangely now the navbar get over width (more than expected), there is a horizontal scroll bar now. this is the code:
<div class="row">
<nav class="navbar navbar-default">
<div class="container">
<section class="">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="collapse navbar-collapse" id="collapse">
<ul class="nav navbar-nav">
<li class="active "><span class="glyphicon glyphicon-home"></span></li>
<li class=" dropdown">text menu<span class="caret"></span>
<ul class="dropdown-menu">
<li>text menu</li><li>text menu</li><li>text menu</li><li>text menu</li>
</ul>
</li>
<li class="" dropdown"="">text menu <span class="caret"></span>
<ul class="dropdown-menu">
<li>text menu</li><li>text menu</li><li>text menu</li>
</ul>
</li>
<li class=" ">text menu</li>
<li class=" ">text menu</li>
<li class="dropdown">text menu <span class="caret"></span>
<ul class="dropdown-menu">
<li>text menu</li>
<li>text menu</li>
</ul></li>
</ul>
<form role="form" class="navbar-form navbar-right" id="formCari" method="GET" action="search">
<div class="form-group has-feedback">
<input type="search" name="q" id="q" class="form-control" placeholder="text menu">
<i class="form-control-feedback glyphicon glyphicon-search " style="position:absolute;/*top:7px;*/"></i>
</div>
</form>
</div>
</section>
</div>
</nav>
</div>
Thank you for your help!
The problem is in the parent .row element, which is making the .navbar to display weirdly.
If you remove the class .row from the first div, it will work properly.
CSS that is causing the problem (from bootstrap)
.row {
margin-right: -15px;
margin-left: -15px;
}
Related
I found a code from
http://usebootstrap.com/theme/facebook
But in this code, I want to make 'Home icon' never be collapsed at any browser size.
CODE:
<div class="navbar navbar-blue navbar-static-top">
<div class="navbar-header">
<button class="navbar-toggle" type="button" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
b
</div>
<nav class="collapse navbar-collapse" role="navigation">
<ul class="nav navbar-nav">
<li>
###▽▽▽ I want this icon remain on the navbar, not in collapsed dropdown menu
<i class="glyphicon glyphicon-home"></i>
###△△△ I want this icon remain on the navbar, not in collapsed dropdown menu
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<i class="glyphicon glyphicon-user"></i>
<ul class="dropdown-menu">
<li>More</li>
<li>More</li>
<li>More</li>
</ul>
</li>
</ul>
</nav>
</div>
Bootply: https://www.bootply.com/lEfd188zDg
I tried to move <i class="glyphicon glyphicon-home"></i> to after b, but it looks very ugly.
I want that 'Home icon' is still seen in smaller browser size, being looks nicely not ugly. How can i modify well?
EDIT
Pic:
This simplified code is a little different from above code that i posted firstly.
Simplified code:
<div class="wrapper">
<div class="box">
<div class="row row-offcanvas row-offcanvas-left">
<div class="column col-sm-12 col-xs-12" id="main">
<!-- top nav -->
<div class="navbar navbar-blue navbar-static-top">
<div class="navbar-header">
<button class="navbar-toggle" type="button" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<nav class="collapse navbar-collapse" role="navigation">
<ul class="nav navbar-nav">
<li>
<i class="glyphicon glyphicon-home"></i>
</li>
<li>
<i class="glyphicon glyphicon-home"></i>
</li>
<li>
<i class="glyphicon glyphicon-home"></i>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<i class="glyphicon glyphicon-user"></i>
<ul class="dropdown-menu">
<li>More</li>
<li>More</li>
</ul>
</li>
</ul>
</nav>
<!-- /top nav -->
</div>
</div>
</div>
</div>
</div>
original result is like:
and in narrow browser,
But purpose result is like:
Would give me the way how to make this?
I just updated your HTML code and added CSS. Just replace it with yours. Please Only tap nav.
<style>
.heading-icons li{
padding: 9px 10px;
margin-top: 8px;
margin-right: 15px;
}
</style>
<div class="navbar navbar-blue navbar-static-top">
<div class="col-xs-6 col-sm-6">
<ul class="list-inline heading-icons">
<li>
<i class="glyphicon glyphicon-home"></i>
</li>
<li>
<i class="glyphicon glyphicon-home"></i>
</li>
<li>
<i class="glyphicon glyphicon-home"></i>
</li>
</ul>
</div>
<div class="navbar-header col-xs-6 col-sm-6">
<button class="navbar-toggle" type="button" data-toggle="collapse"
data-target=".navbar-collapse">
<span class="sr-only">Toggle</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<nav class="collapse navbar-collapse" role="navigation">
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><i
class="glyphicon glyphicon-user"></i></a>
<ul class="dropdown-menu">
<li>More</li>
<li>More</li>
</ul>
</li>
</ul>
</nav>
<!-- /top nav -->
</div>
I want two icons next to each other (nearly no space between them), I put them in same li and same div but they are now blue and not well positionned vertically, what bootstrap class or custom style or anything else should I use (just putting in 2 li doesn't make it, the icons have too much space between them) ? :
https://www.w3schools.com/code/tryit.asp?filename=FD6NR1HEOO3W
#import url('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">WebSiteName</a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li class="active">Home</li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">Page 1 <span class="caret"></span></a>
<ul class="dropdown-menu">
<li>Page 1-1</li>
<li>Page 1-2</li>
<li>Page 1-3</li>
</ul>
</li>
<li>Page 2</li>
<li>Page 3</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>
<div class="btn-group">
<span class="glyphicon glyphicon-user"></span>
<span class="glyphicon glyphicon-log-in"></span>
</div>
</li>
</ul>
</div>
</div>
</nav>
<div class="container">
<h3>Collapsible Navbar</h3>
<p>In this example, the navigation bar is hidden on small screens and replaced by a button in the top right corner (try to re-size this window).
<p>Only when the button is clicked, the navigation bar will be displayed.</p>
</div>
You should not use <div> inside <li>
I have used two different li for both icons and added two classes, check below snippet:
Note: You can adjust space between icons using by increasing padding
#import url('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css');
.navbar-right li{
display:inline-block
}
.navbar-right li .left_padd {
padding-left:0;
}
.navbar-right li .right_padd {
padding-right:0;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">WebSiteName</a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li class="active">Home</li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">Page 1 <span class="caret"></span></a>
<ul class="dropdown-menu">
<li>Page 1-1</li>
<li>Page 1-2</li>
<li>Page 1-3</li>
</ul>
</li>
<li>Page 2</li>
<li>Page 3</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>
<a class="right_padd" href="#"><span class="glyphicon glyphicon-user"></span></a><li>
<li><a class="left_padd" href="#"><span class="glyphicon glyphicon-log-in"></span></a></li>
</li>
</ul>
</div>
</div>
</nav>
<div class="container">
<h3>Collapsible Navbar</h3>
<p>In this example, the navigation bar is hidden on small screens and replaced by a button in the top right corner (try to re-size this window).
<p>Only when the button is clicked, the navigation bar will be displayed.</p>
</div>
The problem is you have <div class="btn-group"> and you don't need it, also you have the two buttons inside only one <li>.
This is your code:
<ul class="nav navbar-nav navbar-right">
<li>
<div class="btn-group">
<span class="glyphicon glyphicon-user"></span>
<span class="glyphicon glyphicon-log-in"></span>
</div>
</li>
</ul>
and should be like this: only one <li> per button, without the btn-group div:
<ul class="nav navbar-nav navbar-right">
<li><span class="glyphicon glyphicon-user"></span></li>
<li><span class="glyphicon glyphicon-log-in"></span></li>
</ul>
Here is an example: https://www.w3schools.com/code/tryit.asp?filename=FD6OLHFYBBWZ
Apply color:white and padding-top to the spans that contain .glyphicon. This should help.
Change the markup for your nabvar containing the glyphicons from this:
<ul class="nav navbar-nav navbar-right">
<li>
<div class="btn-group">
<span class="glyphicon glyphicon-user"></span>
<span class="glyphicon glyphicon-log-in"></span>
</div>
</li>
</ul>
to:
<ul class="nav navbar-nav navbar-right">
<li>
<span class="glyphicon glyphicon-user"></span>
</li>
<li>
<span class="glyphicon glyphicon-log-in"></span>
</li>
</ul>
#import url('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">WebSiteName</a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li class="active">Home</li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">Page 1 <span class="caret"></span></a>
<ul class="dropdown-menu">
<li>Page 1-1</li>
<li>Page 1-2</li>
<li>Page 1-3</li>
</ul>
</li>
<li>Page 2</li>
<li>Page 3</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><span class="glyphicon glyphicon-user"></span></li>
<li><span class="glyphicon glyphicon-log-in"></span></li>
</ul>
</div>
</div>
</nav>
<div class="container">
<h3>Collapsible Navbar</h3>
<p>In this example, the navigation bar is hidden on small screens and replaced by a button in the top right corner (try to re-size this window).
<p>Only when the button is clicked, the navigation bar will be displayed.</p>
</div>
Or, don't create a second navbar at all.
Change:
<ul class="nav navbar-nav navbar-right">
<li>
<div class="btn-group">
<span class="glyphicon glyphicon-user"></span>
<span class="glyphicon glyphicon-log-in"></span>
</div>
</li>
</ul>
to:
<p class="navbar-text navbar-right">
<a class="navbar-link" href="#"><span class="glyphicon glyphicon-user"></span></a>
<a class="navbar-link" href="#"><span class="glyphicon glyphicon-log-in"></span></a>
</p>
#import url('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">WebSiteName</a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li class="active">Home</li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">Page 1 <span class="caret"></span></a>
<ul class="dropdown-menu">
<li>Page 1-1</li>
<li>Page 1-2</li>
<li>Page 1-3</li>
</ul>
</li>
<li>Page 2</li>
<li>Page 3</li>
</ul>
<p class="navbar-text navbar-right">
<a class="navbar-link" href="#"><span class="glyphicon glyphicon-user"></span></a>
<a class="navbar-link" href="#"><span class="glyphicon glyphicon-log-in"></span></a>
</p>
</div>
</div>
</nav>
<div class="container">
<h3>Collapsible Navbar</h3>
<p>In this example, the navigation bar is hidden on small screens and replaced by a button in the top right corner (try to re-size this window).
<p>Only when the button is clicked, the navigation bar will be displayed.</p>
</div>
I'm trying to have "separated" menu items when the navbar is collapsed...
Here's what I tried so far but it doesn't look right when the navbar is not collapsed because the navbar will overflow to two rows:
<nav class="navbar navbar-default navbar-static-top" ng-controller="NavbarCtrl">
<div class="container">
<div class="navbar-header">
<button class="navbar-toggle" type="button" ng-click="isCollapsed = !isCollapsed" data-toggle="collapse"
data-target="#navbar-main">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<img src="favicon-32.png">
</div>
<div collapse="isCollapsed" class="navbar-collapse collapse" id="navbar-main">
<ul class="nav navbar-nav hidden-xs">
<li ng-repeat="item in menu" ng-class="{active: isActive(item.link)}">
<a ng-href="{{item.link}}">{{item.title}}</a>
</li>
</ul>
<!-- Navbar items visible when collapsed -->
<ul class="nav navbar-nav navbar-right visible-xs">
<li ng-hide="isLoggedIn()" ng-class="{active: isActive('/login')}">Login</li>
<li ng-show="isLoggedIn()"><p class="navbar-text">Hello {{ getCurrentUser().name }}</p></li>
<li ng-show="isLoggedIn()" ng-class="{active: isActive('/logout')}">Logout
</li>
</ul>
</div>
<!-- Navbar items visible when not collapsed -->
<ul class="nav navbar-nav navbar-right hidden-xs">
<li ng-hide="isLoggedIn()" ng-class="{active: isActive('/login')}">Login</li>
<li ng-show="isLoggedIn()"><p class="navbar-text">Hello {{ getCurrentUser().name }}</p></li>
<li ng-show="isLoggedIn()" ng-class="{active: isActive('/logout')}">Logout</li>
</ul>
</div>
</nav>
Let's simplifying an example that describes what you need to do
<div class="navbar">
<div class="navbar-inner">
<div class="ps-content">
<button type="button" class="btn btn-navbar visible-phone" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<div class="brand">Navigation</div>
<ul class="nav hidden-desktop hidden-tablet">
<li>Separated link</li>
</ul>
<!-- PS RHS menu items -->
<div class="visible-tablet pull-right">
<ul class="nav">
<li class="active">Active link</li><li class="divider-vertical"></li>
<li>Second link</li><li class="divider-vertical"></li>
<li>Third link</li>
</ul>
</div>
<div class="nav-collapse pull-right">
<ul class="nav pull-right ">
<li class="active text-right">Actives link</li><li class="divider-vertical"></li>
<li class="text-right">Second link</li><li class="divider-vertical"></li>
<li class="text-right">Third link</li>
</ul>
</div>
</div>
</div>
</div>
Check this bootply
This question already has answers here:
Exclude menu item from the collapse of bootstrap 3 navbar
(3 answers)
Closed 6 years ago.
I could use some help getting my Bootstrap 3 navbar to look right when collapsed.
Apologies if this is a duplicate question but a good long search hasn't yielded the answers I need.
I've created a responsive navbar based on the Bootstrap demo code. In it, there's a 40x40 image and a globe glyph that link to dropdown menus, which I've right-aligned and omitted from the nav Collapse.
Unfortunately, the 40x40 and globe glyph appear on a new line when the nav collapses, which I don't want.
My perfect layout when the nav collapses would be for the 40x40 and globe to appear on the same line as my brand image, the collapse button etc; right aligned, and not contained in the collapse.
Thank you for any advice you can give!
Code is like so:
<nav class="navbar navbar-default" role="navigation">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-hd-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<img class="navbar-brand img-responsive" src="http://placehold.it/138x38" alt="Logo">
</div>
<div class="navbar-right">
<ul class="nav" style="float: right; display: inline-block !important">
<li class="dropdown pull-right">
<img src="http://placehold.it/40x40" alt="Profile Image" style="display: inline-block !important"/><b class="caret grey"></b>
<ul class="dropdown-menu">
<li class="dropdown-header">Hello</li>
<li class="divider"></li>
<li>Thing 1</li>
<li class="divider"></li>
<li>Thing 2</li>
</ul>
</li>
</ul>
<ul class="nav" style="float: right; display: inline-block !important">
<li class="dropdown pull-right">
<span class="glyphicon glyphicon-globe grey"></span><b class="caret grey"></b>
<ul class="dropdown-menu">
<li style="padding: 10px"><p>News</p></li>
</ul>
</li>
</ul>
<div class="collapse navbar-collapse navbar-hd-collapse">
<ul class="nav navbar-nav">
<li class="active">Product</li>
<li>Other Product</li>
<li>Third Product</li>
</ul>
</div>
</nav>
JS Fiddle is here: http://jsfiddle.net/CaraGee/q8br8/
Add Style=" float:right"; in the 40*40 and globe div... so that the 40x40 and globe glyph appear on a same line
<div class="navbar-right" style="float:right;">
<ul class="nav">
<li class="dropdown pull-right">
<img src="http://placehold.it/40x40" alt="Profile Image" style="display: inline-block !important"/><b class="caret grey"></b>
<ul class="dropdown-menu">
<li class="dropdown-header">Hello</li>
<li class="divider"></li>
<li>Thing 1</li>
<li class="divider"></li>
<li>Thing 2</li>
</ul>
</li>
</ul>
</div>
<div class="navbar-right" style="float:right">
<ul class="nav">
<li class="dropdown pull-right">
<span class="glyphicon glyphicon-globe grey"></span><b class="caret grey"></b>
<ul class="dropdown-menu">
<li style="padding: 10px"><p>News</p></li>
</ul>
</li>
</ul>
</div>
make a the collapse div with the align to the left:
and the non collapsable elements inside a div with the align to the right
like this:
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="#">Project name</a>
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<!-- THIS WILL COLLAPSE-->
<div class="navbar-collapse collapse navbar-left">
<ul class="nav navbar-nav">
<li class="active">Home</li>
<li>About</li>
<li>Contact</li>
</ul>
</div>
<!-- THIS WILL NOT COLLAPSE -->
<div class="nav navbar-nav" >
<form class="navbar-form navbar-right">
<div class="form-group">
<input type="text" placeholder="Usuario" class="form-control">
</div>
<div class="form-group">
<input type="password" placeholder="Contraseña" class="form-control">
</div>
<button type="submit" class="btn btn-success">Conectarse</button>
</form>
</div>
</div>
</div>
I'm using bootstrap and trying to put a search form inside a navbar dropdown menu, but I'm finding the form looks squashed because the width of the dropdown is too small. Also, the form elements are not how I would like. How do I fix this?
I'm new to CSS and web design in general. Please help!
Current layout:
What I'm trying to achieve:
<header class="navbar navbar-inverse navbar-fixed-top navbar-inverse" role="banner">
<div class="container">
<div class="navbar-header">
<button class="navbar-toggle" type="button" data-toggle="collapse" data-target=".bs-navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
Brand
</div>
<nav class="collapse navbar-collapse bs-navbar-collapse" role="navigation">
<ul class="nav navbar-nav">
<li class="active">Home</li>
<li>Browse</li>
</ul>
<ul class="nav navbar-nav">
<li class="dropdown">
Locate <b class="caret"></b>
<ul class="dropdown-menu">
<form class="navbar-form navbar-left" role="search">
<div class="form-group">
<button type="button" class="btn btn-default navbar-btn"><li class="icon-screenshot"></li></button>
<input type="text" class="form-control" placeholder="Address">
</div>
<div class="btn-group">
<button type="submit" class="btn btn-default">Search</button>
<ul class="dropdown-menu" role="menu">
<li>Link</li>
<li>Link</li>
</ul>
</div>
</form>
</ul>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
USER <b class="caret"></b>
<ul class="dropdown-menu">
<li><i class="icon-pencil"></i> Link</li>
<li><i class="icon-upload"></i> Link</li>
<li class="divider"></li>
<li><i class="icon-signout"></i> Link</li>
</ul>
</li>
</ul>
</nav>
</div>
</header>
Try this:
.navbar-nav>li>.dropdown-menu { width: yourwidth }
You can add display: inline-block so that its width will be according to its content automatically
You can increase the "min-width" value in the dropdown.less
or make a new line in the css
.dropdown-menu { min-width: 200px }