My bootstrap navbar collapse breakpoint wont change - html

i am trying to make my bootstrap navbar collapse if the webpage width is under 1024px but it collapses under 700ish pixels width. I have tried alot of solutions that i googeled but no luck. I have tryed CSS from this post "Bootstrap 3 Navbar Collapse" it has a problem similar to mine. But no matter what i do i just wont collapse after 1024px width. I have tryed copying their html(boostrap navbar)+css just to see if that will work but no luck.
My CSS
#media (max-width: 1024px) {
ul.nav.navbar-nav{
margin-left:-15px;
}
.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;
}
}
My Bootstrap navbar
<nav>
<img class="kopakuttlogo" src="kopakuttlogo.jpg" alt="Logo" width="400" height="400"/>
<div class="navigatsioon">
<div class="navbar navbar-default" role="navigation">
<div class="container">
<!-- 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-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>
<div class="container-fluid">
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>AVALEHT</li>
<li>HINNAKIRI</li>
<li>RENDITINGIMUSED</li>
<li>TEHNIKA</li>
<li></span>KONTAKT</li>
</ul>
</li>
</ul>
</div><!-- /.navigatsioon -->
</div>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>

Hey i got it to work with adding .navigatsioon everywhere
#media (max-width: 1024px) {
.navigatsioon ul.nav.navbar-nav{
margin-left:-15px;
}
.navigatsioon .navbar-header {
float: none;
}
.navigatsioon .navbar-left,.navbar-right {
float: none !important;
}
.navigatsioon .navbar-toggle {
display: block;
}
.navigatsioon .navbar-collapse {
border-top: 1px solid transparent;
box-shadow: inset 0 1px 0 rgba(255,255,255,0.1);
}
.navigatsioon .navbar-fixed-top {
top: 0;
border-width: 0 0 1px;
}
.navigatsioon .navbar-collapse.collapse {
display: none!important;
}
.navigatsioon .navbar-nav {
float: none!important;
margin-top: 7.5px;
}
.navigatsioon .navbar-nav>li {
float: none;
}
.navigatsioon .navbar-nav>li>a {
padding-top: 10px;
padding-bottom: 10px;
}
.navigatsioon .collapse.in{
display:block !important;
}
}

Bootstrap. How to change the navbar collapse breakpoint
Go to the Customize page / Grid system and set in the field #grid-float-breakpoint the value that you need.
Click the Compile and Download button at the bottom of the page.
Extract the files bootstrap.css and bootstrap.min.css from the resulting archive.
Use them instead of the standard files bootstrap.css and bootstrap.min.css on your site.
Nothing else is needed.

Related

How to keep navigation bar collapsed on all screen sizes?

I tried these two different solutions suggested here on SO :
How to keep Bootstrap 3 navbar as collapsed for all screen sizes
Change bootstrap navbar collapse breakpoint without using LESS
I've also tried many other different solutions suggesting more or less the same. None worked for me.
How can I keep Bootstrap 3 navigation bar collapsed on all screen sizes, both big and small?
This is the HTML :
<nav class="navbar navbar-default navbar-custom">
<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="index.html">
<img class="img-responsive imglogoheader" src="images/logo1.png">
</a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li class="">Home</li>
<li>Profile</li>
<li>Settings</li>
<ul style="display:none !important;" class="nav navbar-nav navbar-right"></ul>
</div>
</div>
</nav>
To make the navbar menu toggle-able on all responsive intervals in Bootstrap 3, you need this snippet:
#media (min-width: 768px) {
.navbar {
.navbar-header,
.navbar-nav>li {
float: none;
}
.navbar-nav {
float: none;
margin: 7.5px -15px;
}
.navbar-toggle {
display: block;
margin-right: 0;
}
.navbar-collapse {
border-top: 1px solid transparent;
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1);
}
.navbar-collapse.collapse {
display: none;
}
.navbar-nav>li>a {
padding-top: 10px;
padding-bottom: 10px;
}
.navbar-text {
float: none;
margin: 15px 0;
}
.navbar-collapse.collapse.in {
display: block;
}
.collapsing {
overflow: hidden;
}
}
}
Please note it's SCSS. If you want it as CSS, you could copy/paste it from the demo at the end of the answer.
The solution is largely adapted from this answer but I thought it's worth posting it as a clean one rather then telling you to play with breakpoints and clean it up.
Most importantly, it doesn't use !important.
Feel free to upvote the original answer. It is an exceptional solution to a difficult problem, especially considering the complexity of Bootstrap 3's navbar collapse logic mechanics (it's done by the collapse plugin, in JavaScript - which makes it difficult to debug and/or reverse engineer).
See it working:
#media (min-width: 768px) {
.navbar .navbar-header,
.navbar .navbar-nav>li {
float: none;
}
.navbar .navbar-nav {
float: none;
margin: 7.5px -15px;
}
.navbar .navbar-toggle {
display: block;
margin-right: 0;
}
.navbar .navbar-collapse {
border-top: 1px solid transparent;
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1);
}
.navbar .navbar-collapse.collapse {
display: none;
}
.navbar .navbar-nav>li>a {
padding-top: 10px;
padding-bottom: 10px;
}
.navbar .navbar-text {
float: none;
margin: 15px 0;
}
.navbar .navbar-collapse.collapse.in {
display: block;
}
.navbar .collapsing {
overflow: hidden;
}
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<nav class="navbar navbar-default navbar-custom">
<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="index.html">
Logo
</a>
</div>
<div class="collapse .navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li class="">Home</li>
<li>Profile</li>
<li>Settings</li>
</ul>
</div>
</div>
</nav>
The answer suggested by tao worked at 60% but not all the way for me. Here I share what finally did it for me. In my custom.css I override bootstrap with custom rules
custom.css
#media (min-width: 768px) {
.navbar .navbar-header,
.navbar .navbar-nav>li {
float: none;
}
.navbar .navbar-nav {
float: none;
margin: 7.5px -15px;
}
.navbar .navbar-toggle {
display: block;
margin-right: 0;
}
.navbar .navbar-collapse {
border-top: 1px solid transparent;
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1);
}
.navbar .navbar-collapse.collapse {
display: none;
}
.navbar .navbar-nav>li>a {
padding-top: 10px;
padding-bottom: 10px;
}
.navbar .navbar-text {
float: none;
margin: 15px 0;
}
.navbar .navbar-collapse.collapse.in {
display: block;
}
.navbar .collapsing {
overflow: hidden;
}
}
I had to comment out this line in bootstrap.min.cs to make it all work :
.navbar-collapse.collapse {
/* display:block!important;*/
height:auto!important;
padding-bottom:0;
overflow:visible!important
}

How do I keep the logo from resizing when on mobile?

I believe what is happening is the image is getting shrinked until it disappears, and I want to keep it the same size even on mobile, and also leveled to the rest of the nav li/hamburger
<!DOCTYPE html>
<head>
</head>
<body>
<style>
/* --- header -- */
.navbar-header div.logo {
margin-top: -1%;
padding-bottom: 0;
}
.navbar-header div.logo a.navbar-brand {
padding: 0;
}
.navbar-header div.logo a.navbar-brand img {
width: 6%;
padding: 15px;
}
navbar-nav .navbar-brand {
display: flex;
align-items: center;
}
.navbar-nav .navbar-brand>img {
padding: 7px 14px;
}
/****override navbar height********/
.navbar-nav > li > a {
padding-top: 4px !important;
padding-bottom: 2px !important;
}
.navbar {
min-height: 5px !important
}
/*********************************/
header .navbar {
margin-bottom: 0;
}
.navbar-default {
border: none;
}
header .navbar-collapse ul.navbar-nav {
float: right;
margin-right: 0;
}
header .navbar-default {
background-color: transparent;
}
header .navbar {
min-height: 32px;
}
header .navbar-nav > li {
padding-bottom: 5px;
padding-top: 5px;
}
header .navbar-nav > li > a {
padding-bottom: 5px;
padding-top: 5px;
margin-left: 2px;
line-height: 30px;
font-weight: 700;
}
</style>
<header>
<div class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<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 class="logo">
<a class="navbar-brand" href="index.php"><img src="./img/logo.png"></a>
</div>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>about us</li>
<li>Contacts</li>
</ul>
</div>
</div>
</div>
</header>
<div>content</div>
</body>
Does anyone know how to keep the logo from disappearing, moving or resizing, while keeping the rest of the website elements responsive?
It's because you have set your image to a size in %, you will have to change it to a set size. This:
.navbar-header div.logo a.navbar-brand img {
width: 6%;
padding: 15px;
}
should be something like this:
.navbar-header div.logo a.navbar-brand img {
width: 200px;
padding: 15px;
}

Changing width of Fixed navbar and keeping Collapse element and adding logo/image

i'm trying to change the width of my navbar which is fixed and also has a navbar-collapse property that i want to keep when screen size changes.
I also added in the Bootstrap i am using for this page, so at the moment with the code below, the navbar is fixed but is full width, it collapses when you change to mobile site, so the only thing i want is to change the width from full width so that there is atleast 30% open space on either side of the navbar so it will be centred to the page.
and also adding a logo/image to the navbar only when its collapsed
Hope you can help me!
<html>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<style>
.navbar-nav.nav-justified > li{float:none; }
.navbar{
background-color:white;
font-family: Amatic SC;
border:none;
font-size: 25px;
letter-spacing: 1px;
text-align:center;
}
.navbar:hover,
.navbar:active {
color: black;
transition: background-color 0.3s ease-oin,
color 0.3s ease-out;
}
.navbar-inverse .navbar-nav>li>a:hover {
color: black;
}
#media (max-width: 981px) {
.navbar-left,.navbar-right {
float: none !important;
}
.navbar-toggle {
display: block;
}
.navbar-collapse {
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;
}
}
</style>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top" "col-xs- col-xs-offset-0 col-md-6 col-md-offset-3" >
<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 class="navbar-collapse collapse" style="text-align:center" >
<ul class="nav navbar-nav nav-justified">
<li id="scrollDetails">Details</li>
<li id="scrollDirections">Directions</li>
<li id="navRsvp">RSVP</li>
<li id="scrollBucket">Bucket List</li>
<li id="scrollAccommodation">Accommodation</li>
</ul>
</div>
</nav>
</body>
</html>
You have to modify the width and centrally align your code in the media queries for the expected behaviour in mobile view.
You have to add the following css:
#media (max-width: 981px) {
.navbar {
width: 30%;
margin: auto;
}
}
Refer code:
.navbar-nav.nav-justified > li {
float: none;
}
.navbar {
background-color: white;
font-family: Amatic SC;
border: none;
font-size: 25px;
letter-spacing: 1px;
text-align: center;
}
.navbar:hover,
.navbar:active {
color: black;
transition: background-color 0.3s ease-oin, color 0.3s ease-out;
}
.navbar-inverse .navbar-nav>li>a:hover {
color: black;
}
#media (max-width: 981px) {
.navbar {
width: 30%;
margin: auto;
}
.navbar-left,
.navbar-right {
float: none !important;
}
.navbar-toggle {
display: block;
}
.navbar-collapse {
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;
}
}
<nav class="navbar navbar-inverse navbar-fixed-top col-xs-offset-0 col-md-6 col-md-offset-3">
<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 class="navbar-collapse collapse" style="text-align:center">
<ul class="nav navbar-nav nav-justified">
<li id="scrollDetails">Details
</li>
<li id="scrollDirections">Directions
</li>
<li id="navRsvp">RSVP
</li>
<li id="scrollBucket">Bucket List
</li>
<li id="scrollAccommodation">Accommodation
</li>
</ul>
</div>
</nav>

Modify Bootstrap Collapsed Mobile Menu width. (not editing collapse breakpoint)

I would like to modify the styling on the collapsible part of the Bootstrap menu so it does not stretch the entire width of the mobile screen. I would like to push it in 15px on each side, so when the .navbar-toggle button is tapped and the menu collapses out, you can see the background too. I have tried this:
.navbar-collapse {
padding-right: -15px;
padding-left: -15px;
}
However this did not work. I have put some Photoshop mockups below to help explain what I need to achieve, here is the markup:
<div class="container hidden-lg hidden-md hidden-sm" style="margin-bottom:-20px;">
<nav class="navbar navbar-default">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<div class="row">
<a class="" href="/"><img src="/assets/img/logosmall.png" style="height:30px;" /></a>
<a style="color: white; margin-left:5px;" class="pull-right btn btn-info btn-xs" href="/pay/">Instant Pay</a>
<hr style="border-top: 1px solid #ffc107; padding:0px; margin: 7px 0px 5px 0px">
</div>
<div class="row">
<a class="mobilebar_elements col-xs-5" href="/login/">Login</a>
<a class="mobilebar_elements col-xs-5" href="/signup/">Signup</a>
<button style="padding-top:3px; margin-bottom:3px; margin-top:3px;" type="button" class="navbar-toggle collapsed col-xs-1" 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>
<div>
</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>Home</li>
<li>Tenants & Property Owners</li>
<li>Payment Options</li>
<li>Personalised Payment Page</li>
<li>Contact Us</li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
</div>
CSS (Full CSS Here):
.navbar-collapse {
padding-right: 15px;
padding-left: 15px;
overflow-x: visible;
-webkit-overflow-scrolling: touch;
border-top: 1px solid transparent;
-webkit-box-shadow: inset 0 1px 0 rgba(255, 255, 255, .1);
box-shadow: inset 0 1px 0 rgba(255, 255, 255, .1);
}
.navbar-collapse.in {
overflow-y: auto;
}
#media (min-width: 768px) {
.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-right: 0;
padding-left: 0;
}
}
.navbar-fixed-top .navbar-collapse,
.navbar-fixed-bottom .navbar-collapse {
max-height: 340px;
}
#media (max-device-width: 480px) and (orientation: landscape) {
.navbar-fixed-top .navbar-collapse,
.navbar-fixed-bottom .navbar-collapse {
max-height: 200px;
}
}
.container > .navbar-header,
.container-fluid > .navbar-header,
.container > .navbar-collapse,
.container-fluid > .navbar-collapse {
margin-right: -15px;
margin-left: -15px;
}
#media (min-width: 768px) {
.container > .navbar-header,
.container-fluid > .navbar-header,
.container > .navbar-collapse,
.container-fluid > .navbar-collapse {
margin-right: 0;
margin-left: 0;
}
}
.navbar-static-top {
z-index: 1000;
border-width: 0 0 1px;
}
#media (min-width: 768px) {
.navbar-static-top {
border-radius: 0;
}
}

My bootstrap Toggle is disappearing after it is opened

I'm trying to add bootstrap toggle navigation in 1024 width. I have written a media query for it but after opening the navigation, it suddenly hides.
Here is my css :
#media (max-width: 1024px) {
.navbar-header {
width: 100% !important;
}
.navbar-header .logo {
width: 400px !important;
float: left !important;
}
.responsive-logo {
margin-top: 0px !important;
padding-top: 0px !important;
}
.navbar-toggle {
display: block;
}
.bs-navbar-collapse.collapse {
display: none !important;
}
}
and Html Code :
<div class="container-fluid inverse">
<div class="navbar-header responsive-logo left">
<button class="navbar-toggle active" 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>
<img src="/05/logo2.png" class="img-responsive" alt="">
</div>
<div class="col-md-8">
<nav style="height: auto;" class="navbar-collapse bs-navbar-collapse collapse in" role="navigation" id="site-navigation">
<div class="col-md-7 col-md-offset-1 pdtp10">
<ul id="menu-top-menu" class="nav navbar-nav navbar-left responsive-nav main-nav-list">
<li id="menu-item-723" class="menu-item ">Philosophy</li>
<li id="menu-item-724" class="menu-item">Team</li>
<li id="menu-item-539" class="menu-item">Blog</li>
<li id="menu-item-540" class="menu-item ">Contact</li>
</ul>
</div>
<div class="col-md-4 pdtp20 lpno">
<div class="loginmenu">
<img src="05/user1.png">Angel Logout
</div>
</div>
</nav>
</div>
</div>
Check this DEMO
Add this CSS
#media (max-width: 2000px) {
.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;
}
}
Result