This is an OLD question for Bootstrap 3 -> changing the collapse point for the navbar, but the methodologies suggested here:
https://coderwall.com/p/wpjw4w/change-the-bootstrap-navbar-breakpoint
and here:
Bootstrap 3 Navbar Collapse
do not work for collapsing below 768px, it only seems to work for extending the collapse point, not retracting it. I have a particular situation where my navbar has 3 buttons, so it doesn't need to collapse so early. I would like it to collapse at 420px instead.
Is there a CSS solution to this? If not, can somebody point me towards the correct attribute in the bootstrap customisation page which I need to change and download? Is it the generic breakpoints perhaps? Because there is nothing I can see which says Navbar breakpoints:
http://getbootstrap.com/customize/
As requested, my HTML for the navbar is simply:
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<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="navbar-collapse collapse" id = "navbar">
<ul class="nav navbar-nav navbar-left">
<li class = "navbar_buttons"><a id = "new_route_button"><strong>New Route</strong></a></li>
<li class="divider-vertical"></li>
<li class = "navbar_buttons"><a id = "clear_route_button">Clear Route</a></li>
</ul>
<ul class="nav navbar-nav navbar-right"> <!--Right justified navbar list-->
<li class = "navbar_buttons"><a id = "about_button">About</a></li>
</ul>
</div>
</div> <!-- Container -->
</nav> <!-- End of Navbar Container -->
Then I have some CSS to add a vertical division:
/*Preventing vertical dividers from appearing collapsed*/
#media (max-width: 420px) {
.navbar-collapse .nav > .divider-vertical {
display: none;
}
}
/*Defining the vertical dividers*/
.navbar .divider-vertical {
height: 50px;
margin: 0 9px;
border-right: 1px solid #ffffff;
border-left: 1px solid #DADADA;
}
.navbar-inverse .divider-vertical {
border-right-color: #222222;
border-left-color: #111111;
}
Yes, changing the breakpoint to anything less than 768px is different than changing the breakpoint over 768px. You need to override all of the Bootstrap defaults that normally make it collapse.
#media only screen and (min-width: 420px) {
.collapse {
display: block;
}
.navbar-header {
float: left;
}
.navbar-toggle {
display: none;
}
.navbar-nav.navbar-left {
float: left;
margin: 0;
}
.navbar-nav.navbar-right {
float: right;
margin: 0;
}
.navbar-nav>li {
float: left;
}
.navbar-nav>li>a {
padding-top: 15px;
padding-bottom: 15px;
}
}
#media only screen and (max-width: 420px) {
.collapse {
display: none;
}
.navbar-header {
display: block;
}
}
http://www.bootply.com/wpUuFIZqJ2
The following code snippet is based on the original answer, but also works when there are drop down menus in the navbar.
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<style>
#media only screen and (min-width: 560px) {
.collapse {
display: block;
}
.navbar-header {
float: left;
}
.navbar-toggle {
display: none;
}
.navbar>.container .navbar-brand,
.navbar>.container-fluid .navbar-brand {
margin-left: -15px;
}
.container>.navbar-header,
.container-fluid>.navbar-header,
.container>.navbar-collapse,
.container-fluid>.navbar-collapse {
margin-right: 0;
margin-left: 0;
}
.navbar-nav {
float: left;
margin: 0;
}
.navbar-nav.navbar-right {
float: right;
margin: 0;
}
.navbar-nav>li {
float: left;
}
.navbar-nav>li>a {
padding-top: 15px;
padding-bottom: 15px;
}
.navbar-nav .open .dropdown-menu {
position: absolute;
float: left;
width: auto;
margin-top: 2px;
background-color: #fff;
border: 1px solid #ccc;
border: 1px solid rgba(0, 0, 0, 0.15);
-webkit-box-shadow: 0 6px 12px rgba(0, 0, 0, 0.175);
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.175);
}
.navbar-inverse .navbar-nav .open .dropdown-menu .divider {
background-color: #e5e5e5;
}
.navbar-inverse .navbar-nav .open .dropdown-menu>li>a {
color: #333;
}
.navbar-nav .open .dropdown-menu>li>a {
line-height: 1.42857143;
}
.navbar-nav .open .dropdown-menu>li>a,
.navbar-nav .open .dropdown-menu .dropdown-header {
padding: 3px 20px;
}
.navbar-right .dropdown-menu {
right: 0;
left: auto;
}
}
#media only screen and (max-width: 559px) {
.collapse {
display: none;
}
.navbar-header {
display: block;
}
}
</style>
<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">Link <span class="sr-only">(current)</span></li>
<li>Link</li>
<li class="dropdown">
Dropdown <span class="caret"></span>
<ul class="dropdown-menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li role="separator" class="divider"></li>
<li>Separated link</li>
<li role="separator" class="divider"></li>
<li>One more separated link</li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>Link</li>
<li class="dropdown">
Dropdown <span class="caret"></span>
<ul class="dropdown-menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li role="separator" class="divider"></li>
<li>Separated link</li>
</ul>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container-fluid -->
</nav>
Related
I'm trying to position the hamburger menu on the right when I click on it, but I'm not managing to adjust the CSS for that.
I have this HTML code:
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-header">
<a class="navbar-brand" href="#">Brand</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>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="active">Home</li>
<li>About</li>
<li>Contact</li>
</ul>
<div class="navbar-header">
<p class="navbar-text navbar-right">
Username
</p>
</div>
</div>
</nav>
Ad this CSS:
#media (max-width: 1200px) {
.navbar-header {
float: none;
}
.navbar-left,.navbar-right {
float: none !important;
}
.navbar-toggle {
display: block;
}
.navbar-collapse {
border-top: 1px solid transparent;
box-shadow: inset 0 1px 0 rgba(255,255,255,0.1);
}
.navbar-fixed-top {
top: 0;
border-width: 0 0 1px;
}
.navbar-collapse.collapse {
display: none!important;
}
.navbar-nav {
float: none!important;
margin-top: 7.5px;
}
.navbar-nav>li {
float: none;
}
.navbar-nav>li>a {
padding-top: 10px;
padding-bottom: 10px;
}
.collapse.in{
display:block !important;
}
}
How to adjust this CSS so that the hamburger menu is on the right when clicking on it? The padding of the boxes must be appropriate to the size of the words inside it. Like this:
It's okay if it overwrites the space under it.
I need a solution that uses this CSS code, only. See more here.
Thanks.
Change collapse.in selector to
.collapse.in{
display:block !important;
position:absolute;
float:right;
right: 0;
}
I have created a website using Bootstrap 3. When in responsive mode, my index.html page has a horizontal scroll bar. I could not find what is causing this overflow-x. This only happens in my index.html page.
In the other pages, this overflow is not present. At first I thought it was something in the Contact section of my index.html which has a box shadow which caused the overflow in x. Even after removing it, the overflow was present which made me conclude that the navbar is the one causing the issue.
I am not able to find what is causing this issue.
Screenshot: (the overflow on the right side)
HTML code for navbar:
<header id="main">
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#collapse" 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="">
<!-- <img class="img img-responsive" src="www/images/srs-logo.jpg" alt="SRS Constructions"> -->
SRS Constructions
</a>
</div>
<div class="collapse navbar-collapse navbar-right" id="collapse">
<ul class="nav navbar-nav">
<li class="active"><a class="main" href="#main">Home <span class="sr-only">(current)</span></a>
</li>
<li class="dropdown" id="nav-about">
<a href="#about" class="dropdown-toggle main" role="button" aria-haspopup="true" aria-expanded="false">About
</a>
<ul class="dropdown-menu" style="left:0;right: auto">
<li>The Founder</li>
<li role="separator" class="divider"></li>
<li>HSE Policy</li>
<li>Quality Policy</li>
</ul>
</li>
<li><a class="main" href="#services">Services</a></li>
<li><a class="main" href="#projects">Our Projects</a></li>
<li><a class="main" href="#whyus">Why Us</a></li>
<li><a class="main" href="#contact">Contact</a></li>
</ul>
</div>
</div>
</nav>
</header>
I have not added any specific css which alters the width of the navbar.
CSS for navbar:
/*Navbar styles*/
.navbar {
box-shadow: 0 3px 3px rgba(0, 0, 0, 0.3);
}
.navbar-default .navbar-nav {
font-size: 15px;
}
.navbar-fixed-top {
min-height: 80px;
}
.navbar-nav > li > a {
padding-top: 0px;
padding-bottom: 0px;
line-height: 80px;
}
.dropdown-menu > .active > a,
.dropdown-menu > .active > a:hover,
.dropdown-menu > .active > a:focus {
color: #ffffff;
text-decoration: none;
outline: 0;
background-color: #b4a28f;
}
#media (max-width: 767px) {
.navbar-nav > li > a {
line-height: 30px;
padding-top: 10px;
padding-bottom: 10px;
}
.navbar-brand > img {
width: 40%;
position: relative;
display: inline-block;
height: auto;
margin-left: 90px;
margin-top: -80px;
}
#footer {
color: #2e2e2e;
}
}
#media (min-width: 767px) {
#footer {
color: #ffffff;
}
}
.navbar-brand > img {
width: 30%;
position: relative;
display: inline-block;
height: auto;
margin-left: 50px;
margin-top: -15px;
}
The site is also available here
Please help me with fixing this issue.
Make sure you follow the "rules" for the grid...
Columns .col-* must be wrapped in .row, and only .col-* should be the immediate child of a .row
.row > .gallery in the projects section is causing the scrollbar since .gallery is not a column.
Is it possible to center the navbar vertically and horizontally?
/**
* Logo.
*/
.button-logo {
font-family: 'Monoton', cursive;
font-weight:normal;
font-size:40px;
font-weight: 300;
line-height: 40px;
letter-spacing: 1px;
}
.button-logo:hover {
text-decoration: none;
}
.button-logo span {
display: block;
clear:both;
color: #000;
}
/**
* Centerise the logo.
*/
.navbar-header {
float: left;
text-align: center;
width: 100%;
}
.navbar-brand {
float:none;
}
/**
* Centerise the navbar.
*/
.navbar .navbar-nav {
display: inline-block;
float: none;
}
.navbar .navbar-collapse {
text-align: center;
}
/**
* Remove default background, radius, etc.
*/
.navbar {
-webkit-border-radius: 0;
-moz-border-radius: 0;
border-radius: 0;
border: 0;
background: none;
box-shadow: none;
margin-bottom: 0;
}
.navbar-default .navbar-nav > li > a {
font-family: 'Monoton', cursive;
font-size: 25px;
letter-spacing: 2px;
color: #000;
color: rgba(0, 0, 0, 0.5);
padding-bottom: 0 !important;
}
.navbar-default .navbar-nav > li > a:hover {
color: #000;
}
.navbar-default .navbar-nav > .active > a,
.navbar-default .navbar-nav > .active > a:hover,
.navbar-default .navbar-nav > .active > a:focus {
background: none;
background: none;
box-shadow: none;
color: #000;
}
<!-- Static navbar -->
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="offcanvas" data-target=".navmenu" data-canvas="body">
<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 button-logo" href="#">
<span>brand</span>
<span>brand</span>
<span>brand</span>
</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<!-- menu-box -->
<div class="menu-box">
<ul class="nav navbar-nav">
<li class="active">Home</li>
<li>About</li>
<li>Contact</li>
</ul>
</div>
<!-- menu-box -->
</div><!--/.nav-collapse -->
</div><!--/.container-fluid -->
</nav>
But this only centers the navbar horizontally not vertically.
Any ideas?
jsfiddle
to place your navbar in the center of your screen you can simply add
nav {
position: fixed;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
https://jsfiddle.net/anpvtaxu/1/
If Igot your question correctly :
.navbar .navbar-nav {
display: inline-block;
float: none;
}
.navbar .navbar-collapse {
text-align: center;
}
<div class="container">
<nav class="navbar navbar-default" role="navigation">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-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>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse navbar-ex1-collapse">
<ul class="nav navbar-nav">
<li>Link</li>
<li>Link</li>
<li>Link</li>
<li>Link</li>
<li class="dropdown">
Dropdown <b class="caret"></b>
<ul class="dropdown-menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li>Separated link</li>
<li>One more separated link</li>
</ul>
</li>
</ul>
</div><!-- /.navbar-collapse -->
</nav>
</div>
[UPDATE]
Above is for horizontal center;If you want it to be centered vertically use:
top:50%;
in every element you want it be centered vertically.
first post on SO so sorry if my format is horrible. Just a quick question about a custom fixed-top navbar I'm working on (and I'm very new to Bootstrap and CSS in general). It has a logo as the brand, and three links on the right, one of which is a dropdown, there's also a media query for the the links to collapse sooner (which I found here on SO!). However, when the window is re-sized, and the collapse button is clicked all of the links drop down on the complete left side like it's coming from under the brand. I just want a simple accordion style dropdown for the collapse and for the actual dropdown. Any input is very much appreciated!
Here is the HTML:
<nav class="navbar navbar-default navbar-fixed-top">
<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="#topFixedNavbar1" 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="#"><img src="images/logo.jpg" alt="Top Tier Math"></a></div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="topFixedNavbar1">
<ul class="nav navbar-nav navbar-right links">
<li>How We Work</li>
<li>Abous Us</li>
<li class="dropdown">Dropdown<span class="caret"></span>
<ul class="dropdown-menu dropdown-menu-right">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li role="separator" class="divider"></li>
<li>Separated link</li>
</ul>
</li>
</ul>
</div>
I also added some css to change the height of the navbar for the logo but I doubt this is the cause. Here it is though.
.navbar-default{
height:120px;
}
.navbar-header, .navbar-brand{
height:120px;
padding-top: 0px;
padding-right: 0px;
padding-bottom: 0px;
padding-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
margin-left: 0px;
}
#topFixedNavbar1{
height:120px;
}
.links{
height:120px;
}
.navbar-nav li a{
line-height:90px;
}
.dropdown li a{
line-height:30px;
}
#media (max-width: 991px) {
.navbar-header {
float: none;
}
.navbar-toggle {
display: block;
}
.navbar-collapse {
border-top: 1px solid transparent;
box-shadow: inset 0 1px 0 rgba(255,255,255,0.1);
}
.navbar-collapse.collapse {
display: none!important;
}
.navbar-nav {
float: none!important;
margin: 7.5px -15px;
}
.navbar-nav>li {
float: none;
}
.navbar-nav>li>a {
padding-top: 10px;
padding-bottom: 10px;
}
.navbar-text {
float: none;
margin: 15px 0;
}
/* since 3.1.0 */
.navbar-collapse.collapse.in {
display: block!important;
}
.collapsing {
overflow: hidden!important;
}
}
I'm not sure how you want them to display but just use CSS to control the position of the dropdown.
.collapse.navbar-collapse {
width:
margin:
}
You should be able to add styles to this and it will move and change the dropdown.
This may be tricky to answer/explain properly but:
Building small website for school project. Using bootstrap. When screen is below 780px the nav bar turns into the mobile design with the button icon when clicked has the dropdown menu.
The issue is the menu is meant to push content under it down when its open but it is just going over my content on some page/ under a slideshow i have on main page and it is unclickable as the content sits over it.
I've tried to include all relevant code, it is a complete mess however. Because of all the HTML/CSS and bootstrap and jquery links it's too hard to post in a jfiddle.
Can anyone see anything that would be wrong??
Here is a screenshot of the problem:
http://imgur.com/c5WMDZi
HTML:
<!-- Start of nav bar -->
<div class="bottomHeader">
<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">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<!-- 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>Home</li>
<li class="dropdown">
Products<span class="caret"></span>
<ul class="dropdown-menu" role="menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li class="divider"></li>
<li>Separated link</li>
</ul>
</li>
<li class="dropdown">
Services<span class="caret"></span>
<ul class="dropdown-menu" role="menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li class="divider"></li>
<li>Separated link</li>
</ul>
</li>
<li class="dropdown">
Deals<span class="caret"></span>
<ul class="dropdown-menu" role="menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li class="divider"></li>
<li>Separated link</li>
</ul>
</li>
<li>My Account</li>
<li class="dropdown searchDropDown">
Search<span class="caret"></span>
<ul class="dropdown-menu" role="menu">
<li><form role="search">
<input type="text" class="form-control searchBox" placeholder="Search">
<button type="submit" class="btn btn-default">Submit</button>
</form>
</li>
</ul>
</li>
</ul>
<!-- SEARCH BUTTON -->
<div class="searchSection">
<form class="searchRight" role="search">
<input type="text" class="form-control searchBox" placeholder="Search">
<button type="submit" class="btn btn-default">Submit</button>
</form>
</div>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
</div> <!-- end bottom header div -->
</div> <!-- end header div -->
</header>
<!-- START OF PAGE CONTENT -->
<content>
<div class="background">
<div class="container2">
<div class="trial"> BOO<br>BOO<br>BOO<br>BOO<br>BOO<br>BOO<br>
</div>
</div>
</div>
</content>
</html>
CSS:
.headerBox {
background-color: #0076a3;
width: 100%;
margin: 0 auto;
height: 115px;
}
.topHeader {
background-color: transparent;
}
.dellImgBox {
padding-left: 42px;
background-color: transparent;
}
.socialMediaBox {
float: right;
margin-right: 53px;
padding-top: 5px;
}
.smImg {
background-color: transparent;
margin-right: 5px;
display: inline-block;
}
.smImgLeft {margin-left: 30px;}
.socialMediaBox a:hover {
background: transparent;
}
/******* Bottom Header ********/
.bottomHeader {
border: 0px solid black;
background-color: transparent;
height: 53px;
}
.navbar-default {
background-color: transparent;
border: 0px;
}
.navbar-header {
float: right;
}
.trial {
margin: 20px 20px;
border: 1px solid black;
min-height: 300px;
color: #444;
}
/* Have nav on right position & display DDmenu */
#media screen and (min-width: 772px) {
.container > .navbar-header,
.container-fluid > .navbar-header,
.container > .navbar-collapse,
.container-fluid > .navbar-collapse {
margin-right: 30px;
margin-left: 0;
margin-top: -13px;
}
ul.nav li.dropdown:hover > ul.dropdown-menu {
display: block;
}
}
#media screen and (max-width: 771px) {
.topHeader {display:none;}
.headerBox {height: 55px;}
ul.nav.navbar-nav {width: 260px;}
}
/* Hide Main Search input field # Xwidth */
#media screen and (max-width: 882px) {
.searchSection {display: none;}
.searchDropDown {display: block;}
}
#media screen and (min-width: 883px) {
.searchDropDown {
display: none!important;
}
}
In your CSS file you should remove height: 53px; and it will work.
.bottomHeader {
border: 0px solid black;
background-color: transparent;
height: 53px;
}
Change to this one:
.bottomHeader {
border: 0px solid black;
background-color: transparent;
}
That's because you have overrided navbar-default class and added background-color:transparent. Just comment it and you can find it on the top of all.
DEMO
.navbar-default {
/*background-color: transparent;*/
border: 0px;
z-index:100000;//Add this property
}