Helo guys, I want to modify the navbar in order to collapse on #screen-md :992px;.
I have modified navbar.less, but still not working and I don't know what to do.
So how can I modify the #grid-float-breakpoint variable in order to have that menu collapsed on custom media query size?
FIDDLE:
You can change the collapse point in 3.1 like this..
#media (max-width: 992px) {
.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;
}
}
http://www.bootply.com/120951
In Bootstrap 4, changing the breakpoint is easier. See this answer
In variables.less change
#grid-float-breakpoint: #screen-sm-min
to
#grid-float-breakpoint: #screen-md-min;
or to whatever other width you would like.
It's easy and painless done this way.
Here is the code I used to solve this, just add it to your style sheet.
#media (max-width: 1992px) {
.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;
}
}
If you are using Twitter Bootstrap, the responsive collapse is already built in. You may just have to invoke it with a class in your menu. But this is the css I use in most of the Bootstrap applications I've worked with, including the one I working in right now
#media(min-width:768px) {
.navbar-collapse {
width: auto;
/* more code here */
}
change the min width to the width you want it to collapse from.
Related
I'm a novice, so please excuse me.
I am making a site for work, and using bootstrap. I have a login drop down in the navbar. It looks fine on desktop view, but when scaled way down for mobile view, the once you click the login button or drop down it gets jerky and then the navbar gray bar extends down and just looks all screwed up. HELP!
Here's links.
https://web.gettips.com/redesign7/index.html
https://web.gettips.com/redesign7/css/styles.css
Below is the code for the media queries:
#charset "UTF-8";
/* CSS Document */
#media (max-width: 375px) {
.title {
padding-top: 270px;
}
}
#media only screen and (max-width: 400px) {
.title {
padding-top: 0;
font-size: 12px;
}
#toplogin img {
width: 60px;
height: auto !important;
}
}
#media only screen and (max-width: 767px) {
.footer-bs .footer-nav,
.footer-bs .footer-social,
.footer-bs .footer-ns {
border-left: solid 1px rgba(255, 255, 255, 0.10);
}
#toplogin img {
width: 90px;
height: auto !important;
}
}
#media only screen and (max-width: 773px) {
.title {
padding-top: 5px;
font-size: 15px;
}
#toplogin img {
width: 90px;
height: auto !important;
}
}
#media only screen and (max-width: 1029px) {
.title {
padding-top: 5px;
font-size: 20px;
}
#toplogin img {
width: 100px;
height: auto !important;
}
.panel-heading h1 {
font-size: 25px;
}
}
#media (max-width: 1118px) {
.header img {
width: 80px;
height: auto !important;
}
.navbar-header {
float: none;
}
.navbar-toggle {
display: block;
padding: 3px;
}
.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: 0px -15px;
}
.navbar-nav>li {
float: none;
}
.navbar-nav>li>a {
padding-top: 5px;
padding-bottom: 5px;
}
.navbar-text {
float: none;
margin: 15px 0;
}
/* since 3.1.0 */
.navbar-collapse.collapse.in {
display: block!important;
}
.collapsing {
overflow: hidden!important;
}
.dropdown-menu {
font-size: 16px;
}
}
Its because you are add width 100% after click... Add to the div width 100% before click, so when you click on button, the div already have a correct width. See, I add a custom class and define a width.
I changed the breakpoint for the bootstrap navbar using this code:
#media (max-width: 1000px) {
.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;
overflow-y: auto;
}
.collapsing {
overflow: hidden!important;
}
.navbar-nav .open .dropdown-menu {
position: static;
float: none;
width: auto;
margin-top: 0;
background-color: transparent;
border: 0;
-webkit-box-shadow: none;
box-shadow: none;
}
}
My problem is that between 768px and the new breakpoint, the menu goes out of the nav container, and i want it to behave like in mobile (stay inside container and add a vertical scroll bar). I may be mising some css but no idea what :(
EDIT: Here you have the jsfiddle https://jsfiddle.net/nato522/e71e8bfd/
EDIT2: also, a picture to show the problem
navbar issue
Try This CSS:
#media (max-width: 1000px) {
.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;
overflow-y: auto!important;
overflow-x: hidden!important;
}
.collapsing {
overflow: hidden!important;
}
.navbar-nav .open .dropdown-menu {
position: static;
float: none;
width: auto;
margin-top: 0;
background-color: transparent;
border: 0;
-webkit-box-shadow: none;
box-shadow: none;
}}
This question already has answers here:
Bootstrap 3 Navbar Collapse
(12 answers)
Closed 6 years ago.
Currently when the browser width drops below 768px, the .navbar changes to collapsed mode. I want to change this width to 992px so when the browser is below 992px the .navbar changes to collapsed mode.. I am using bootstrap 3.3.6
I am using this code but it doesn't work for me
#media screen and (max-width: 992px) {
.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;
}
}
I was looking for exactly the same thing and I found this , It works 100%!
You need to add this css
#media (max-width: 992px) {
.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;
}
}
Also you need this javascript
$('#monitor').html($(window).width());
$(window).resize(function() {
var viewportWidth = $(window).width();
$('#monitor').html(viewportWidth);
});
If it doesn't work, answer me those questions...
Do you use navbar-fixed-top ?
Do you use navbar-inverse?
Take a look at my html code it might help you...
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<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>
<!-- This is the main nav menu content -->
<div id="navbar" class="collapse navbar-collapse">
<ul class="nav navbar-nav hover-effect">
<li>Home</li>..........
The recommended approach is to use Bootstrap's 'Customize and download' function to customize Bootstrap to your requirement.
Alternatively you could change your media query, but you might end up overriding a bunch of classes:
#media (min-width: 768px) and (max-width: 992px) {
.collapse {
display: none !important;
}
}
This works, and the navbar collapses at 992px with the css code below:
#media (min-width: 992px) {
.navbar-right .dropdown-menu {
left: auto;
right: 0;
}
.navbar-right .dropdown-menu-left {
left: 0;
right: auto;
}
}
#media (min-width: 992px) {
.navbar-header {
float: left;
}
}
#media (min-width: 992px) {
.navbar-collapse {
width: auto;
border-top: 0;
-webkit-box-shadow: none;
box-shadow: none;
}
.navbar-collapse.collapse {
display: block !important;
height: auto !important;
padding-bottom: 0;
overflow: visible !important;
}
.navbar-collapse.in {
overflow-y: visible;
}
.navbar-fixed-top .navbar-collapse,
.navbar-static-top .navbar-collapse,
.navbar-fixed-bottom .navbar-collapse {
padding-left: 0;
padding-right: 0;
}
}
#media (min-width: 992px) {
.container > .navbar-header,
.container-fluid > .navbar-header,
.container > .navbar-collapse,
.container-fluid > .navbar-collapse {
margin-right: 0;
margin-left: 0;
}
}
#media (min-width: 992px) {
.navbar-fixed-top,
.navbar-fixed-bottom {
border-radius: 0;
}
}
#media (min-width: 992px) {
.navbar-fixed-top,
.navbar-fixed-bottom {
border-radius: 0;
}
}
#media (min-width: 992px) {
.navbar > .container .navbar-brand,
.navbar > .container-fluid .navbar-brand {
margin-left: -15px;
}
}
#media (min-width: 992px) {
.navbar-toggle {
display: none;
}
}
#media (min-width: 992px) {
.navbar-nav {
float: left;
margin: 0;
}
.navbar-nav > li {
float: left;
}
.navbar-nav > li > a {
padding-top: 15px;
padding-bottom: 15px;
}
}
#media (min-width: 992px) {
.navbar-form {
width: auto;
border: 0;
margin-left: 0;
margin-right: 0;
padding-top: 0;
padding-bottom: 0;
-webkit-box-shadow: none;
box-shadow: none;
}
}
#media (min-width: 992px) {
.navbar-text {
float: left;
margin-left: 15px;
margin-right: 15px;
}
}
#media (min-width: 992px) {
.navbar-left {
float: left !important;
}
.navbar-right {
float: right !important;
margin-right: -15px;
}
.navbar-right ~ .navbar-right {
margin-right: 0;
}
}
I have tried the following code with bootstrap 3.3.6 and it works.
#media (max-width: 996px) {
.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;
}
}
Please check this jsfiddle
I am having some problems with the alignment of the links inside the navbar for the mobile version of my site. When looking at the desktop version, everything is ok. It looks like this:
Code:
.navbar {
margin-top: 30px;
min-height: 50px;
padding: 0;
background-color: red;
background-image: none;
filter: -;
border: none;
-webkit-border-radius: none;
-moz-border-radius: none;
border-radius: none;
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
*zoom: 1;
}
.navbar-inner {
background-color: fuchsia;
background-image: none;
border: none;
border-radius: 0;
box-shadow: none;
}
.navbar li a,
.navbar .nav > li > a:hover {
margin-left: 20px;
background-color: #5593f8;
webkit-border-radius: 6px;
-moz-border-radius: 6px;
border-radius: 6px;
}
Now for the mobile version. It looks like this at the moment:
Code:
#media (max-width: 767px) {
body {
padding-right: 0;
padding-left: 0;
}
.navbar {
margin-top: 0px;
}
.navbar .nav > li {
float: none;
text-align: center;
}
.navbar li a,
.navbar .nav > li > a:hover {
margin: 0;
}
.navbar .nav {
width: 100%;
background: red;
}
.navbar-inner {
padding: 0;
margin: 0;
}
}
Do you see that small gap on the left where the fuchsia can be seen? I don't want that. I want the links to be width: 100%, but somehow that's not possible. I spend nearly the whole day to figure out what the problem is, but I can't wrap my head around it. Its not margin, its not padding, but what is it? Please help me.
Ok, I got it!
After the media query posted above, I had this:
#media (max-width: 979px) {
.navbar {
margin-top: 0px;
}
.navbar-inner {
padding-left: 5px;
}
}
The 5px declared in the last rule are gap you see in the post above. Moving the rule from this post above the rule from the first post did solve the problem.
I'm trying to make my sidebar fluid so it adjusts with the browser window, and everything seems to be working great, except for the fact that with the media query added, my CSS styling breaks, but when I take the query away it is back to the norming styling from my stylesheet. Can someone look at my code and tell me what I'm doing wrong? Thanks in advance!
BTW, when I add the second ending curly brace to the #rightandoverview media query, the styling go back to the way it should, but the fluidity doesn't work. What could it be?
#righthandoverview {
position: absolute;
top: 91px;
right: 0px;
width: 20%;
height:215px;
background-color: white;
webkit-box-shadow: 0px 4px 5px -5px #777;
-moz-box-shadow: 0px 4px 5px -5px #777;
box-shadow: 0px 4px 5px -5px #777;
}
#media screen and (max-width:830px) and (min-width:100px) {
#righthandoverview {
float: left;
width: 30%;
background-color: yellow;
margin-top: 5px;
}
#righthandoverview ul {
position: absolute;
display: inline;
float: left;
font-family: klavika-light;
list-style-type: none;
text-decoration: none;
white-space: nowrap;
}
#media screen and (max-width:830px) and (min-width:100px) {
#righthandoverview ul {
float:left;
width:30%;
background-color: yellow;
margin-top: 10px;
}
}
#righthandoverview ul li > a {
display: inline;
text-decoration: none;
color:#8BAFDA;
}
#righthandoverview ul li {
padding-bottom: 6px;
}
Looks like you are missing a bracket to end your first media query
#media screen and (max-width:830px) and (min-width:100px) {
#righthandoverview {
float: left;
width: 30%;
background-color: yellow;
margin-top: 5px;
}
#righthandoverview ul {
position: absolute;
display: inline;
float: left;
font-family: klavika-light;
list-style-type: none;
text-decoration: none;
white-space: nowrap;
}
}
you missed a bracket in the following code, i have added it.
#media screen and (max-width:830px) and (min-width:100px) {
#righthandoverview {
float: left;
width: 30%;
background-color: yellow;
margin-top: 5px;
}
}