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
Related
I have before element which show's line bottom.
Is this possible to add margin right to this before element that it will one space for example 20 pixels in every screen sizes.
Right now as you can see I'm adding space from right with manipulating width property .In here this space didn't show'n.
Please help.
body {
overflow-x:hidden;
}
.link_more {
margin-left: auto;
text-align: right;
position: relative;
z-index: -1
}
.link_more a {
text-decoration: none;
font-size: 18px;
font-weight: 700;
color: #000;
}
#media only screen and (max-width: 768px) {
.link_more a {
margin-right:0
}
}
.link_more a:before {
content: "";
position: absolute;
border-bottom: 1px solid #000;
width: 9.6%;
top: 25px
}
#media only screen and (max-width: 768px) {
.link_more a:before {
width:16%;
}
}
#media only screen and (max-width: 1200px) {
.link_more a:before {
width:10%
}
}
#media only screen and (max-width: 992px) {
.link_more a:before {
width:9.6%
}
}
#media only screen and (max-width: 568px) {
.link_more a:before {
width:calc(100% - 73.7vw)
}
}
#media only screen and (min-width: 1200px) {
.main_wallpaper .main_content .link_more a:before {
content:"";
position: absolute;
border-bottom: 1px solid #000;
width: 8.6%;
top: 25px
}
}
<div class="link_more">
more
</div>
If you want right margin of 20px, You can use right:20px; instead of width
.link_more a {
text-decoration: none;
font-size: 18px;
font-weight: 700;
color: #000;
right:20px;
position:relative;
}
.link_more a:before {
content: "";
position: absolute;
border-bottom: 1px solid #000;
width: 100%;
top: 25px
right:20px;
}
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 have a bootstrap nav fixed top with height of 120px, the nav itself looks as I want. but when it goes mobile size the links are the same height as the nav bar. I cannot figure out what I am missing..
.navbar {
background-color: rgba(0, 0, 0, .6);
box-shadow: 1px 1px 4px 0 rgba(0, 0, 0, .1);
min-height:120px !important;
}
.navbar-nav > ul, li {
padding: 0px 15px;
}
.contain-pull{
max-width: 93%;
margin: 0 auto 0 auto;
}
.navbar-nav > li > a, .navbar-brand {
padding-top:50px !important;
padding-bottom:0 !important;
height: 120px;
}
.navbar a {
color: #fff !important;
text-transform: uppercase;
font-size: 14px;
font-weight: 300px;
font-family: 'Oswald', sans-serif;
text-decoration: none;
}
.navbar a:hover{
color:#258faf !important;
}
.navbar {
border: 0px;
}
.logo {
display: block;
text-decoration: none;
max-height: 95px;
margin: 12px 0px 0px 0px;
width: auto;
}
#media (max-width: 960px) {
.navbar-header {
float: none;
}
.navbar-left,.navbar-right {
float: none !important;
}
.navbar-toggle {
display: block;
margin-top: 40px;
}
.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;
}
}
You can simple place your link rules inside of a media query:
#media (min-width: 960px) {
.navbar.navbar-tall .navbar-nav > li > a {
padding-top: 50px;
padding-bottom: 0;
height: 120px;
}
}
This example keeps the link height at the default settings once the navbar has collapsed.
Working Example: Open Example with FullPage and reduce the browser size.
.navbar.navbar-tall {
background-color: rgba(0, 0, 0, .6);
box-shadow: 1px 1px 4px 0 rgba(0, 0, 0, .1);
min-height: 120px;
border: 0px;
}
.navbar.navbar-tall .navbar-nav > li > a {
color: #fff;
text-transform: uppercase;
font-size: 14px;
font-weight: 300px;
font-family: 'Oswald', sans-serif;
text-decoration: none;
}
.navbar.navbar-tall .navbar-nav > li > a:hover {
color: #258faf;
}
.navbar.navbar-tall .navbar-brand {
padding-top: 50px;
padding-bottom: 0;
height: 120px;
}
#media (min-width: 960px) {
.navbar.navbar-tall .navbar-nav > li > a {
padding-top: 50px;
padding-bottom: 0;
height: 120px;
}
}
#media (max-width: 959px) and (min-width: 768px) {
.navbar.navbar-fixed-bottom .navbar-collapse,
.navbar.navbar-fixed-top .navbar-collapse {
max-height: auto;
overflow-x: visible;
}
}
#media (max-width: 959px) {
.navbar .navbar-header {
float: none;
}
.navbar .navbar-left,
.navbar .navbar-right {
float: none !important;
}
.navbar .navbar-right {
margin-right: 0px;
}
.navbar .navbar-right~.navbar-right {
margin-right: 0;
}
.navbar .navbar-toggle {
display: block;
margin-top: 42.50px;
}
.navbar .navbar-collapse {
border-top: 1px solid transparent;
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1);
}
.navbar.navbar-fixed-top {
top: 0;
border-width: 0 0 1px;
}
.navbar .navbar-collapse.collapse {
display: none!important;
overflow: visible!important;
}
.navbar .navbar-nav {
float: none!important;
margin-top: 7.5px;
}
.navbar .navbar-nav>li {
float: none;
}
.navbar .navbar-nav>li>a {
padding-top: 10px;
padding-bottom: 10px;
}
.navbar .collapse.in {
display: block !important;
overflow-y: auto;
}
.navbar .navbar-nav .dropdown-menu > li > a,
.navbar .navbar-nav .dropdown-menu > li > a:hover,
.navbar .navbar-nav .dropdown-menu > li > a:focus {
color: #777;
}
.navbar .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;
}
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="navbar navbar-inverse navbar-fixed-top navbar-tall">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Brand</a>
</div>
<div class="navbar-collapse collapse" id="navbar">
<ul class="nav navbar-nav navbar-right">
<li>Link
</li>
<li>Link
</li>
<li>Link
</li>
</ul>
</div>
</div>
</div>
<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>
it is normal that the height you put for large screen for the navbar (120px) will be seen in the small devices.
Keep the height of the Navbar small.
Incase if you want to increase height of navbar in large device you can play with
padding of the <a> (anchor inside the nav)
If you observe the toggle button in html it throws a class;
class="navbar-toggle collapsed" data-toggle="collapse"
and when the toggle-button is open it throws the class as;
class="navbar-collapse collapse in"
now according to as above class you can style your navbar <a>tags.
i hope this heps you in something to trying to achieve.
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;
}}
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.