I created a 'mega menu' with Bootstrap 3.
I'm having trouble getting the row that creates the mega-menu horizontally centered and retaining functionality. Element in question has class .mega-dropdown-menu.
<ul class="dropdown-menu mega-dropdown-menu row">
Here's the code snippet pertaining to my issue :
body {
background: #f0f0f0;
}
.dropdown-menu {
background-color: #f5f5f5;
}
.navbar-header {
background-color: #3a7dbb;
}
.collapse.navbar-collapse.js-navbar-collapse {
background-color: #3a7dbb;
/* ?=border-bottom: 5px solid #214f82 */
}
.navbar-default .navbar-nav > li > a.dropdown-toggle {
font-size: 16px;
color: white;
}
.dropdown > .dropdown-menu > li > a {
font-size: 16px;
}
.glyphicon-shopping-cart:before {
color: white;
}
.navbar .navbar-brand {
padding-top: 0px;
}
.dropdown > .dropdown-menu > li > a:hover {
background-color: white;
}
.navbar-nav > li > .dropdown-menu {
background-color: #f5f5f5;
margin-top: 20px;
border-top-left-radius: 4px;
border-top-right-radius: 4px;
}
.navbar-default .navbar-nav > li > a {
/* width: 8em; */
font-weight: bold;
}
.mega-dropdown {
position: static !important;
width: 100%;
}
.mega-dropdown-menu {
padding: 20px 0px;
width: 100%;
box-shadow: none;
-webkit-box-shadow: none;
}
.center {
margin: auto;
}
.mega-dropdown-menu > li > ul {
padding: 0;
margin: 0;
}
.mega-dropdown-menu > li > ul > li {
list-style: none;
}
.mega-dropdown-menu > li > ul > li > a {
display: block;
padding: 3px 20px;
clear: both;
font-weight: normal;
line-height: 1.428571429;
color: #262626;
white-space: normal;
}
.i-am-centered {
margin: auto;
max-width: 300px;
}
.mega-dropdown-menu > li ul > li > a {
font-size: 16px;
}
.mega-dropdown-menu > li ul > li > a:hover,
.mega-dropdown-menu > li ul > li > a:focus {
text-decoration: none;
color: #444;
background-color: white;
}
li.dropdown:hover {
background-color: #c3c1c1;
}
ul.dropdown-menu.mega-dropdown-menu.row {
width: 80%;
}
.mega-dropdown-menu .dropdown-header {
color: #428bca;
font-size: 18px;
font-weight: bold;
}
.mega-dropdown-menu .dropdown-header > a {
color: #428bca;
font-size: 18px;
font-weight: bold;
padding-left: 0;
}
.mega-dropdown-menu form {
margin: 3px 20px;
}
.mega-dropdown-menu .form-group {
margin-bottom: 3px;
}
.navbar-default .navbar-nav .open .dropdown-menu > li > a {
color: black !important;
}
#media only screen and (min-width: 768px) {
.dropdown:hover > .dropdown-menu {
display: block;
}
.dropdown > .dropdown-toggle:active {
pointer-events: none;
}
}
/* .mega-dropdown-menu:before {
content: "";
border-bottom: 15px solid #fff;
border-right: 17px solid transparent;
border-left: 17px solid transparent;
position: absolute;
top: -15px;
left: 285px;
z-index: 10;
}
.mega-dropdown-menu:after {
content: "";
border-bottom: 17px solid #ccc;
border-right: 19px solid transparent;
border-left: 19px solid transparent;
position: absolute;
top: -17px;
left: 283px;
z-index: 8;
} */
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>
<!------ Include the above in your HEAD tag ---------->
<div class="">
<nav class="navbar navbar-default">
<div class="navbar-header">
<button class="navbar-toggle" type="button" data-toggle="collapse" data-target=".js-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>
<a class="navbar-brand" href="#"><img src="https://brm.institute/wp-content/themes/brmi/images/brm-institute-logo.png"></a>
</div>
<div class="collapse navbar-collapse js-navbar-collapse">
<ul class="nav navbar-nav">
<li class="dropdown mega-dropdown">
Dummy MegaMenu<span class="caret"></span>
<ul class="dropdown-menu mega-dropdown-menu row">
<li class="col-sm-4">
<ul>
<li class="dropdown-header">Dresses</li>
<li>Unique Features</li>
<li>Image Responsive</li>
<li>Auto Carousel</li>
<li>Newsletter Form</li>
<li>Four columns</li>
<li class="divider"></li>
<li class="dropdown-header">Tops</li>
<li>Good Typography</li>
</ul>
</li>
<li class="col-sm-4">
<ul>
<li class="dropdown-header">Jackets</li>
<li>Easy to customize</li>
<li>Glyphicons</li>
<li>Pull Right Elements</li>
<li class="divider"></li>
<li class="dropdown-header">Pants</li>
<li>Coloured Headers</li>
<li>Primary Buttons & Default</li>
<li>Calls to action</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
<!-- /.nav-collapse -->
</nav>
</div>
Code available on codepen as well.
Any help would be appreciated,
Thank you
For your current problem, set .mega-dropdown-menu to either :
01 Using translate :
left: 50% /* instead of 0 */
transform: translateX(-50%);
02 Using margins (prefered solution IMO)
left: 0;
right: 0;
margin: 0 auto; /* Centers the element */
Not enough Rep to add a comment sorry.
I always found:
margin-right: auto;
margin-left: auto;
Does the trick without a need to set a left/right position.
You can also used the class "center-block" built in to Bootstrap 3 to apply this css as a class.
Personally I would recommend updating to Bootstrap 4, took me a while to make the leap but the flexgrid is such an improvement its worth it. Most of the classes are interchangeable to some degree, though in bootstrap 4 "center-block" is now "mx-auto"
I'm new in website development. I have some problem that I cant's solve myself. for your information I'have used template from Zerotheme. Here the link you can download to view the full source code.
Q > How to hide the second level because I want to use "Hover" on the Submenu.
Screenshot
Can someone help me to solve this.
#menu {
border-radius: 0;
text-transform: uppercase;
background: #fff;
}
body.sub-page #menu {
padding: 10px 0;
}
#menu.navbar {
margin: 0;
min-height: auto
}
#menu #heading {
float: left;
padding-left: 15px;
font-size: 20px;
font-weight: 700;
line-height: 40px;
color: #fff;
margin-top: 10px;
text-transform: uppercase;
}
#menu .navbar-brand {
margin: 0;
height: auto;
padding: 0px 18px;
}
#menu .navbar-brand img {
max-width: 160px;
}
#menu .logo {}
#menu .dropdown-menu {
background-color: #EDD9C0;
border: none;
border-radius: 0;
}
#menu ul.nav .dropdown-menu li a {
color: #1a1c1e;
}
#menu ul.nav .dropdown-menu li a:hover {}
#menu .dropdown-inner {
display: table;
}
#menu .dropdown-inner ul {
display: table-cell;
}
#menu .dropdown-inner a {
min-width: 160px;
display: block;
padding: 3px 20px;
clear: both;
line-height: 20px;
color: #000;
margin: 0 5px;
}
#menu li.dropdown:hover>a,
#menu li.dropdown:focus>a,
#menu li.dropdown:active>a {
color: #3B3A36;
background: none;
}
#menu ul.nav li {
padding-right: 16px;
}
#menu ul.nav li a {
padding: 8px 10px;
color: #333;
font-size: 14px;
font-weight: bold;
}
#menu ul.nav li.dropdown a {}
#menu .nav>li>a:hover,
#menu .nav>li>a:focus {
color: #3B3A36;
background: none;
}
#menu .btn-navbar {
font-size: 20px;
color: #FFF;
padding: 5px 15px;
float: right;
border: 3px solid #fff;
}
#media (min-width: 768px) {
#menu ul.nav.navbar-nav {
margin-top: 5px;
display: inline-block;
float: none;
}
#menu .dropdown:hover .dropdown-menu {
display: block;
}
#menu .navbar-collapse {
text-align: center;
}
body.sub-page #menu ul.nav.navbar-nav {
margin-top: 5px;
display: block;
float: right;
}
}
#media(max-width:767px) {
#menu {
background: #1D2027;
padding: 10px 0;
}
#menu .navbar-brand {
display: block;
color: #fff;
margin-top: 10px;
}
#menu div.dropdown-inner>ul.list-unstyled {
display: block;
}
#menu .dropdown-inner a {
width: 100%;
color: #fff;
}
#menu div.dropdown-menu {
margin-left: 0 !important;
padding-bottom: 10px;
background-color: rgba(0, 0, 0, 0.1);
}
#menu ul.nav li a {
color: #fff;
}
#menu ul.nav li a:hover {
color: #EDD9C0;
}
#menu ul.nav li.dropdown a {
color: #fff;
}
}
.dropdown-submenu {
position: relative;
}
.dropdown-submenu>.dropdown-menu {
top: 0;
left: 100%;
margin-top: -6px;
margin-left: -1px;
-webkit-border-radius: 0 6px 6px 6px;
-moz-border-radius: 0 6px 6px 6px;
border-radius: 0 6px 6px 6px;
}
.dropdown-submenu:hover>.dropdown-menu {
display: block;
}
.dropdown-submenu>a:after {
display: block;
content: " ";
float: right;
width: 0;
height: 0;
border-color: transparent;
border-style: solid;
border-width: 5px 0 5px 5px;
border-left-color: #cccccc;
margin-top: 5px;
margin-right: -10px;
}
.dropdown-submenu:hover>a:after {
border-left-color: #ffffff;
}
.dropdown-submenu.pull-left {
float: none;
}
.dropdown-submenu.pull-left>.dropdown-menu {
left: -100%;
margin-left: 10px;
-webkit-border-radius: 6px 0 6px 6px;
-moz-border-radius: 6px 0 6px 6px;
border-radius: 6px 0 6px 6px;
}
<!--Navigation-->
<nav id="menu" class="navbar">
<div class="container-fluid">
<div class="navbar-header">
<span id="heading" class="visible-xs">Categories</span>
<button type="button" class="btn btn-navbar navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse"><i
class="fa fa-bars"></i></button>
</div>
<div class="collapse navbar-collapse navbar-ex1-collapse">
<ul class="nav navbar-nav">
<li class="active">Home</li>
<li>About Us</li>
<li class="dropdown">Category <i class="fa fa-chevron-down"></i>
<div class="dropdown-menu">
<div class="dropdown-inner">
<ul class="list-unstyled">
<li>Text 301</li>
<li>Text 302</li>
<li>Text 303</li>
<li>Text 304</li>
<li>Text 305</li>
<li class="dropdown-submenu"><a tabindex="-1" href="#">Text 314</a>
<ul class="dropdown-menu">
<li>Second level</li>
<li>Second level</li>
</ul>
</li>
</ul>
</div>
</div>
</li>
<li>Blog</li>
<li>Contact</li>
</ul>
</div>
</div>
</nav>
First of all change css of
#menu .dropdown:hover .dropdown-menu {display: block;}
to
#menu .dropdown:hover>.dropdown-menu {display: block;}
because on hover of dropdown show both dropdown-menu and remove
#menu .dropdown-inner {display: table;}
#menu .dropdown-inner ul {display: table-cell;}
because its override display:none without hover
#menu {border-radius: 0;text-transform: uppercase;background: #fff;}
body.sub-page #menu {padding: 10px 0;}
#menu.navbar{margin: 0;min-height:auto}
#menu #heading {float: left;padding-left: 15px;font-size: 20px;font-weight: 700;line-height: 40px;color: #fff;margin-top: 10px;text-transform: uppercase;}
#menu .navbar-brand{margin: 0;height: auto;padding: 0px 18px;}
#menu .navbar-brand img{max-width: 160px;}
#menu .logo {}
#menu .dropdown-menu {background-color: #EDD9C0;border:none;border-radius: 0;}
#menu ul.nav .dropdown-menu li a{color: #1a1c1e;}
#menu ul.nav .dropdown-menu li a:hover{}
#menu .dropdown-inner a {min-width: 160px;display: block;padding: 3px 20px;clear: both;line-height: 20px;color: #000;margin: 0 5px;}
#menu li.dropdown:hover>a, #menu li.dropdown:focus>a, #menu li.dropdown:active>a{color: #3B3A36;background: none;}
#menu ul.nav li{padding-right: 16px;}
#menu ul.nav li a{padding: 8px 10px;color: #333;font-size: 14px;font-weight: bold;}
#menu ul.nav li.dropdown a{}
#menu .nav > li > a:hover, #menu .nav > li > a:focus{color:#3B3A36;background: none;}
#menu .btn-navbar {font-size: 20px;color: #FFF;padding: 5px 15px;float: right;border: 3px solid #fff;}
#media (min-width: 768px) {
#menu ul.nav.navbar-nav {margin-top: 5px;display: inline-block;float: none;}
#menu .dropdown:hover>.dropdown-menu {display: block;}
#menu .navbar-collapse {text-align: center;}
body.sub-page #menu ul.nav.navbar-nav {margin-top: 5px;display: block;float: right;}
}
#media(max-width:767px) {
#menu{background: #1D2027;padding: 10px 0;}
#menu .navbar-brand {display: block;color: #fff;margin-top: 10px;}
#menu div.dropdown-inner > ul.list-unstyled {display: block;}
#menu .dropdown-inner a {width: 100%;color: #fff;}
#menu div.dropdown-menu {margin-left: 0 !important; padding-bottom: 10px;background-color: rgba(0, 0, 0, 0.1);}
#menu ul.nav li a{color: #fff;}
#menu ul.nav li a:hover{color: #EDD9C0;}
#menu ul.nav li.dropdown a{color: #fff;}
}
.dropdown-submenu{position:relative;}
.dropdown-submenu>.dropdown-menu{top:0;left:100%;margin-top:-6px;margin-left:-1px;-webkit-border-radius:0 6px 6px 6px;-moz-border-radius:0 6px 6px 6px;border-radius:0 6px 6px 6px;}
.dropdown-submenu:hover>.dropdown-menu{display:block;}
.dropdown-submenu>a:after{display:block;content:" ";float:right;width:0;height:0;border-color:transparent;border-style:solid;border-width:5px 0 5px 5px;border-left-color:#cccccc;margin-top:5px;margin-right:-10px;}
.dropdown-submenu:hover>a:after{border-left-color:#ffffff;}
.dropdown-submenu.pull-left{float:none;}.dropdown-submenu.pull-left>.dropdown-menu{left:-100%;margin-left:10px;-webkit-border-radius:6px 0 6px 6px;-moz-border-radius:6px 0 6px 6px;border-radius:6px 0 6px 6px;}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<!--Navigation-->
<nav id="menu" class="navbar">
<div class="container-fluid">
<div class="navbar-header">
<span id="heading" class="visible-xs">Categories</span>
<button type="button" class="btn btn-navbar navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse"><i class="fa fa-bars"></i></button>
</div>
<div class="collapse navbar-collapse navbar-ex1-collapse">
<ul class="nav navbar-nav">
<li class="active">Home</li>
<li>About Us</li>
<li class="dropdown">Category <i class="fa fa-chevron-down"></i>
<div class="dropdown-menu">
<div class="dropdown-inner">
<ul class="list-unstyled">
<li>Text 301</li>
<li>Text 302</li>
<li>Text 303</li>
<li>Text 304</li>
<li>Text 305</li>
<li class="dropdown-submenu"><a tabindex="-1" href="#">Text 314</a>
<ul class="dropdown-menu">
<li>Second level</li>
<li>Second level</li>
</ul>
</li>
</ul>
</div>
</div>
</li>
<li>Blog</li>
<li>Contact</li>
</ul>
</div>
</div>
</nav>
The snippet isnt working but my question is for some reason the navbar on resizing the browser does not look the same as when it is viewed in the mobile phone and I am not sure why I am using media queries, attached are photos.
Desktop version of navbar
On an iphone 6
.navbar-default .navbar-nav > li > a:hover {
text-decoration: none;
color: #0064a4;
}
.navbar {
border-radius: 0;
padding: 10px 0;
margin: 0px;
}
.navbar-brand {
height: 70px;
padding: 0 0 0 20px;
}
.navbar-collapse {
padding-left: 20px;
}
.navbar-default .navbar-toggle .icon-bar {
background-color: #fff;
}
#navbar5 {
font-family: 'Oswald', sans-serif;
margin: 0;
float: right;
background-color: #00a7d7;
}
.navbar-default {
background-color: #00a7d7;
border: none;
}
.navbar-default .navbar-nav > li > a {
color: #fff;
}
.navbar-default .navbar-nav > .active > a,
.navbar-default .navbar-nav > .active > a:hover,
.navbar-default .navbar-nav > .active > a:focus {
color: #0064a4;
background-color: transparent;
}
.navbar-toggle {
/* padding:13px 10px; */
}
.navbar-default .navbar-toggle:hover,
.navbar-default .navbar-toggle:focus {
background-color: #0096C1;
}
.navbar-default .navbar-nav > .open > a,
.navbar-default .navbar-nav > .open > a:hover,
.navbar-default .navbar-nav > .open > a:focus {
background-color: #00a7d7;
color: #0064a4;
}
ul.dropdown-menu {
background-color: #00a7d7;
border: none;
box-shadow: none;
}
ul.dropdown-menu a {
color: #fff;
}
#media (min-width: 992px) {
.anon>.col-md-offset-0 {
margin: 0 12%;
}
.navbar-brand img {
width: 75px;
}
}
#media (max-width: 991px) {
.navbar-brand img {
width: 120px;
}
body {
padding-top: 89px;
}
.navbar-header {
float: none;
height: 120px;
}
.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 {
font-size: 50px;
line-height: 50px;
padding-top: 10px;
padding-bottom: 10px;
}
.navbar-text {
float: none;
margin: 15px 0;
}
.navbar-default .navbar-toggle .icon-bar {
width: 40px;
height: 4px;
margin: 8px 0;
}
.navbar-toggle {
padding: 20px;
}
/* since 3.1.0 */
.navbar-collapse.collapse.in {
display: block!important;
}
.collapsing {
overflow: hidden!important;
}
}
<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>
<div class="example5">
<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="#navbar5">
<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="index.html">
<img src="img/logo.png" alt="cophyright logo">
</a>
</div>
<div id="navbar5" class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li class="active">ABOUT
</li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="copyright.html">
COPYRIGHT
<span class="caret"></span></a>
<ul class="dropdown-menu">
<li>WHAT IS COPYRIGHT?
</li>
<li>WORKS INCLUDED
</li>
<li>WORKS EXCLUDED
</li>
<li>COPYRIGHTS
</li>
<li>LIMITATIONS
</li>
<li>OWNERSHIP
</li>
<li>TERM OF PROTECTION
</li>
</ul>
</li>
<li>PROTECTION
</li>
<li>CONTACT US
</li>
</ul>
</div>
<!--/.nav-collapse -->
</div>
<!--/.container-fluid -->
</nav>
</div>
I think bootstrap.min.css overwrite your custom css. So call this sequence: First call bootstrap then custom.css
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<link href="https:custom.css" rel="stylesheet" />
I have a navbar where I show different logos depending on the size of the screen. This is how the html for it looks like:
#media (max-width: 767px) {
.logo-big {
display: block;
}
.logo-small {
display: none;
}
}
The full css is here:
.header {
background-image: url('/img/goal-cover.jpeg');
}
.navbar .navbar-nav > li > a {
color: inherit;
padding-top: 0;
padding-bottom: 0;
font-weight: 400;
font-size: 12px;
border-radius: 3px;
line-height: 58px;
}
b, strong {
font-weight: bold;
color: white;
}
#search {
text-align:center;
text-align: center;
line-height: 57px;
font-size: 16px;
}
input {
width: 200px;
padding: 0 20px;
}
input,
input::-webkit-input-placeholder {
font-size: 16px;
letter-spacing: 0.5px;
border: 0;
background-color: #fff;
color: #3c3e42!important;
}
.btn.btn-primary, .btn.btn-primary:hover, .btn.btn-primary:focus, .btn.btn-primary:active, .btn.btn-primary.active, .btn.btn-primary:active:focus, .btn.btn-primary:active:hover, .btn.btn-primary.active:focus, .btn.btn-primary.active:hover, .open > .btn.btn-primary.dropdown-toggle, .open > .btn.btn-primary.dropdown-toggle:focus, .open > .btn.btn-primary.dropdown-toggle:hover, .navbar .navbar-nav > li > a.btn.btn-primary, .navbar .navbar-nav > li > a.btn.btn-primary:hover, .navbar .navbar-nav > li > a.btn.btn-primary:focus, .navbar .navbar-nav > li > a.btn.btn-primary:active, .navbar .navbar-nav > li > a.btn.btn-primary.active, .navbar .navbar-nav > li > a.btn.btn-primary:active:focus, .navbar .navbar-nav > li > a.btn.btn-primary:active:hover, .navbar .navbar-nav > li > a.btn.btn-primary.active:focus, .navbar .navbar-nav > li > a.btn.btn-primary.active:hover, .open > .navbar .navbar-nav > li > a.btn.btn-primary.dropdown-toggle, .open > .navbar .navbar-nav > li > a.btn.btn-primary.dropdown-toggle:focus, .open > .navbar .navbar-nav > li > a.btn.btn-primary.dropdown-toggle:hover {
background-color: #00bcd4;
color: #FFFFFF;
}
.btn-full-width {
width: 100%;
}
.card {
display: inline-block;
position: relative;
width: 100%;
border-radius: 3px;
background: rgba(41, 39, 39, 0.9);
color: #fff;
box-shadow: 0 2px 2px 0 rgba(0, 0, 0, 0.14), 0 3px 1px -2px rgba(0, 0, 0, 0.2), 0 1px 5px 0 rgba(0, 0, 0, 0.12);
}
.card-signup .content {
padding: 0px 30px 0px 30px;
}
.big-logo-circle {
margin: auto;
width: 180px;
height: 180px;
margin-top: 50px;
padding: 20px 0;
border-radius: 50%;
background: rgba(41, 39, 39, 0.9);
display: flex;
align-items: center;
justify-content: center;
}
.signup-page .wrapper .card-signup {
margin: 50px 0 40px;
}
.btn-red {
background: #e90052;
width: 100%;
}
.btn-red:hover, .btn-red:focus, .btn-red:active, .btn-red a:active{
background: rgba(233, 0, 82, 0.8)!important;
}
.btn-blue {
background: #096b7d;
width: 100%;
}
.btn-blue:hover, .btn-blue:focus, .btn-blue:active, .btn-blue a:active{
background: rgba(9, 107, 125, 0.8)!important;
}
body {
background-color: #ddd;
}
.navbar-toggle .icon-bar {
background-color: #333;
}
.navbar-nav > li {
line-height: 50px;
position: relative;
margin-left: 15px;
margin-right: 15px;
}
.logo, .navbar-nav > li > .btn {
margin: 0 15px;
height: 41px;
margin-top: 4px;
box-shadow: none;
color: #fff;
}
.logo {
background: transparent;
height: 32px;
margin-top: 5px;
}
.navbar-nav > li > .btn {
background: rgba(0, 188, 212);
display: flex;
align-items: center;
margin-top: 8px!important;
box-shadow: none!important;
width: 100px;
}
.navbar-nav > li > .btn:hover, .navbar-nav > li > .btn:focus, .navbar-nav > li > .btn:active {
box-shadow: none!important;
background: rgba(0, 188, 212, 0.8)!important;
}
.logo-big {
display: none;
}
#media (min-width: 767px) {
.navbar-search-form {
position: absolute;
left: 0;
right: 0;
margin: auto;
width: 100%;
float: none;
text-align: center;
padding: 8px 0;
}
.logo {
margin-left: 0;
}
}
#media (max-width: 767px) {
.navbar-search-form {
padding-left: 0;
padding-right: 0;
}
.navbar .navbar-form .form-group .form-control, .navbar .navbar-form .form-control {
width: 400px;
}
.logo-big {
display: block;
}
.logo-small {
display: none;
}
}
#media (max-width: 500px) {
.navbar-search-form {
padding-left: 0;
}
.navbar .navbar-form .form-group .form-control, .navbar .navbar-form .form-control {
width: 300px!important;
}
}
.navbar .navbar-form .form-group {
margin: 0;
padding: 0;
height: 39px;
border: 1px solid;
border-radius: 3px;
line-height: 39px;
background-color: #fff;
}
.navbar .navbar-form {
margin: 0;
}
.navbar-header {
margin-top: 6px;
}
.navbar-form .input-group {
float: left;
}
.input-group .input-group-addon {
padding: 6px 12px;
color: #00bcd4;
}
.navbar .navbar-form .form-group .form-control, .navbar .navbar-form .form-control {
width: 400px;
background-image: none;
}
<nav class="navbar navbar-fixed-top" 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="#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>
<a class="navbar-brand logo-small" href="{{ url('/') }}">
<img class="logo" src="{{ asset('/img/logo-small.png') }}" alt="logo">
</a>
<a class="navbar-brand logo-big" href="{{ url('/') }}">
<img class="logo" src="{{ asset('/img/m2.png') }}" alt="logo">
</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<form class="navbar-form navbar-search-form active" role="search">
<div class="form-group">
<div class="input-group">
<span class="input-group-addon">
<i class="material-icons">search</i>
</span>
<input type="text" class="form-control" placeholder="Search for videos or players..." autofocus>
</div>
</div>
</form>
<ul class="nav navbar-nav navbar-right">
<li>
Sign in
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container-fluid -->
</nav>
And I am changing the logos like this in the css as you can see in code snippet.
But the link for the small brand logo is not working, I can't click on it, when I resize the screen to smaller size and get the bigger logo, then I can click on it and it works. Not sure how to fix that, why can't I click on the small logo on bigger screens?
Set your .navbar-header relative and above with z-index.
.navbar-header {
position: relative;
z-index:1;
}
Working Fiddle
I don't really see anything wrong with your code, but why not use bootstrap default classes?
<img src="logo-small.jpg">
<img src="logo-big.jpg">
The problem is your form, you set width of your form to 100% and it is covering your logo on larger screens.
#media (min-width: 767px) {
.navbar-search-form {
width: 300px;
}
}
.navbar .navbar-form {
margin: auto;
}
Change it to for example 300px, add margin auto and see what happens.
Try this as follow:
.logo-big {
float:left
}
Using bootstrap.
I changed breakpoint to collapse menu in 991px.
Menu are collapsing, but stays expended in sm. Works fine in xs.
It looks like collapsing, but is not disappearing.
Can't figure put whats is causing that.
Link below.
https://jsfiddle.net/marko_lt/spa8Ls1d/
<div class="navbar navbar-default navbar-fixed-top" role="navigation" id="meniu">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#meniucollapse" 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 class="logo-box">
<a class="navbar-brand" href="{% url 'home' %}">
<img id="logotipas" src="{% static 'images/log_pure_small.jpg' %}" alt="logo"/>
</a>
</div>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="meniucollapse">
<ul class="nav navbar-nav">
<li><a data-toggle="collapse" data-target="#meniucollapse" href="#paslaugos" ><span>1 link </span></a></li>
<li><a data-toggle="collapse" data-target="#meniucollapse" href="#marsrutas"><span>2 link </span></a></li>
<li><a data-toggle="collapse" data-target="#meniucollapse" href="#kainos"><span>3 link </span></a></li>
<li><a data-toggle="collapse" data-target="#meniucollapse" href="#taisykles"><span>4 link </span></a></li>
<li><a data-toggle="collapse" data-target="#meniucollapse" href="#kontaktai"><span>5 link </span></a></li>
</ul>
</div>
</div>
</
CSS:
.navbar-default {
background-image:none;
background-color: #373737;
}
/*BIG SCREENS*/
#media all and (min-width: 991px) {
.navbar-default .navbar-nav>.active>a,
.navbar-default .navbar-nav > li > a {
width: 120px;
height: 65px;
font-size: 16px;
border-left: 10px solid #178ACC;
transform: skewX(-45deg);
background-color: #000;
color: #f4ebeb;
}
.navbar-default .navbar-nav > li > a >span {
display:inline-block;
transform: skewX(45deg);
vertical-align: middle;
padding-top: 5px;
padding-left: 2px;
}
.navbar-default .navbar-nav > .active #uzsakymo-linkas {
background-color: #FC6607;
color:#fff;
margin:0px;
width:160px;
border-right: 10px solid #178ACC;
}
.navbar-default .navbar-nav > li>#uzsakymo-linkas > span {
padding-top: 0px;
padding-left: 0px;
text-align: center;
}
} /*end of big screens*/
/*SMALL SCREENS*/
#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-default .navbar-nav>.active>a,
.navbar-nav>li>a
{
padding-top: 5px;
padding-bottom: 5px;
color: #727272;
width: 500px;
border-left: 5vw solid #178ACC;
height: 40px;
font-size: 16px;
color: #f4ebeb;
background-color: #000;
}
.navbar-default .navbar-nav > li > a >span {
display:inline-block;
vertical-align: middle;
padding-top: 5px;
padding-left: 2px;
}
.navbar-text {
float: none;
margin: 15px 0;
}
/*.navbar-collapse .collapse .in { */
.navbar-collapse .collapse .in {
display: block!important;
}
.collapsing {
overflow: hidden!important;
}
} /*end small screens*/
I changed your css-code for small-screen to css-code I used before and it worked fine, of course, I put your properties for li a span:
#media (max-width: 990px) {
.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-default .navbar-nav>.active>a,
.navbar-nav>li>a {
padding-top: 5px;
padding-bottom: 5px;
color: #727272;
width: 500px;
border-left: 5vw solid #178ACC;
height: 40px;
font-size: 16px;
color: #f4ebeb;
background-color: #000;
}
.navbar-default .navbar-nav > li > a > span {
display:inline-block;
vertical-align: middle;
padding-top: 5px;
padding-left: 2px;
}
.navbar-text {
float: none;
margin: 15px 0;
}
/* since 3.1.0 */
.navbar-collapse.collapse.in {
display: block!important;
}
.collapsing {
overflow: hidden!important;
}
}
jsfiddle-link