How to put a dropdown inside another in bootstrap 3? - html

I'm designing a sidebar for mobile and trying to create a dropdown within another dropdown using bootstrap 3 but I do not get it and I do not understand what happens.
When I try to access the dropdown within another one, the two dropdown closes and I do not understand what I should do.
I think it's css problem but I do not know what happens.
//function sidebar
window.onload = function() {
window.jQuery ? $(document).ready(function() {
$(".sidebarNavigation .navbar-collapse").hide().clone().appendTo("body").removeAttr("class").addClass("sideMenu").show(), $("body").append("<div class='overlay'></div>"), $(".navbar-toggle").on("click", function() {
$(".sideMenu").addClass($(".sidebarNavigation").attr("data-sidebarClass")), $(".sideMenu, .overlay").toggleClass("open"), $(".overlay").on("click", function() {
$(this).removeClass("open"), $(".sideMenu").removeClass("open")
})
}), $(window).resize(function() {
$(".navbar-toggle").is(":hidden") ? $(".sideMenu, .overlay").hide() : $(".sideMenu, .overlay").show()
})
}) : console.log("sidebarNavigation Requires jQuery")
};
$(document).ready(function() {
// dropdown animation
$('.dropdown').on('show.bs.dropdown', function(e) {
$(this).find('.dropdown-menu').first().stop(true, true).slideDown(250);
});
$('.dropdown').on('hide.bs.dropdown', function(e) {
$(this).find('.dropdown-menu').first().stop(true, true).slideUp(0);
});
});
.overlay,
.sideMenu {
position: fixed;
bottom: 0
}
.overlay {
top: 0;
left: -100%;
right: 100%;
margin: auto;
background-color: rgba(0, 0, 0, .4);
z-index: 998;
transition: all ease 20ms
}
.sideMenu,
.sidebarNavigation {
z-index: 999;
margin-bottom: 0
}
.overlay.open {
left: 0;
right: 0
}
.sidebarNavigation .left-navbar-toggle {
float: left;
margin-right: 0;
margin-left: 15px
}
.sideMenu {
left: -100%;
top: 52px;
transition: all ease-in-out .4s;
overflow: hidden;
width: 100%;
max-width: 50%
}
.sideMenu.open {
left: 0;
display: block;
overflow-y: auto
}
.sideMenu ul {
margin: 0
}
.navbar-inverse .navbar-toggle:hover,
.navbar-inverse .navbar-toggle:focus {
background-color: #69306d;
}
.navbar .navbar-toggle {
background-color: #91209a;
border-color: #8f4195;
}
.navbar-inverse .navbar-nav>li>a {
color: #fff;
}
.navbar-inverse .navbar-nav>.active>a,
.navbar-inverse .navbar-nav>.active>a:hover,
.navbar-inverse .navbar-nav>.active>a:focus {
color: #fff;
background-color: #91209a;
}
.navbar-inverse .navbar-nav>.open>a,
.navbar-inverse .navbar-nav>.open>a:hover,
.navbar-inverse .navbar-nav>.open>a:focus {
background-color: #91209a;
color: #fff;
}
.navbar-inverse .navbar-nav .open .dropdown-menu>li>a {
color: #fff;
}
.carousel-control i {
position: relative !important;
}
.open>.dropdown-menu {
-webkit-transform: scale(1, 1);
transform: scale(1, 1);
}
.dropdown-menu {
-webkit-transform-origin: top;
transform-origin: top;
-webkit-animation-fill-mode: forwards;
animation-fill-mode: forwards;
-webkit-transform: scale(1, 0);
display: block;
transition: all 0.2s ease-out;
-webkit-transition: all 0.2s ease-out;
}
.dropdown .dropdown-toggle:after {
display: none;
}
.navbar-inverse .navbar-nav>li>a {
padding-top: 10px !important;
padding-bottom: 10px !important;
padding-left: 15px !important;
}
.navbar-inverse .navbar-nav .open .dropdown-menu>li>a {
padding-top: 10px !important;
padding-bottom: 10px !important;
padding-left: 25px !important;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
<nav class="navbar navbar-inverse sidebarNavigation" data-sidebarClass="navbar-inverse" style="background-color: #904296;border-color:#904296;border-color: #8f4195;position:fixed;top:0px;width: 100%;">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle left-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" style="color:white;" href="#">My sidebar</a>
</div>
<div class="collapse navbar-collapse" id="myNavbar" style="background-color: #8f4195;border-color:#8f4195;">
<ul class="nav navbar-nav animated">
<li>Home</li>
<li class="dropdown">About <b class="caret"></b>
<ul role="menu" class="dropdown-menu" aria-labelledby="drop2">
<li class="dropdown">About <b class="caret"></b>
<ul role="menu" class="dropdown-menu" aria-labelledby="drop2">
<li role="presentation">Taaaaa</li>
<li role="presentation">Caaaaers</li>
<li role="presentation">aaaaaars</li>
</ul>
</li>
<li role="presentation">Team Bios</li>
<li role="presentation">Customers</li>
<li role="presentation">Careers</li>
</ul>
</li>
</ul>
</div>
</div>
</nav>

try this
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<style>
body {
font-family: "Lato", sans-serif;
}
/* Fixed sidenav, full height */
.sidenav {
height: 100%;
width: 200px;
position: fixed;
z-index: 1;
top: 0;
left: 0;
background-color: #111;
overflow-x: hidden;
padding-top: 20px;
}
/* Style the sidenav links and the dropdown button */
.sidenav a, .dropdown-btn {
padding: 6px 8px 6px 16px;
text-decoration: none;
font-size: 20px;
color: #818181;
display: block;
border: none;
background: none;
width: 100%;
text-align: left;
cursor: pointer;
outline: none;
}
/* On mouse-over */
.sidenav a:hover, .dropdown-btn:hover {
color: #f1f1f1;
}
/* Main content */
.main {
margin-left: 200px; /* Same as the width of the sidenav */
font-size: 20px; /* Increased text to enable scrolling */
padding: 0px 10px;
}
/* Add an active class to the active dropdown button */
.active {
background-color: green;
color: white;
}
/* Dropdown container (hidden by default). Optional: add a lighter background color and some left padding to change the design of the dropdown content */
.dropdown-container {
display: none;
background-color: #262626;
padding-left: 8px;
}
/* Optional: Style the caret down icon */
.fa-caret-down {
float: right;
padding-right: 8px;
}
/* Some media queries for responsiveness */
#media screen and (max-height: 450px) {
.sidenav {padding-top: 15px;}
.sidenav a {font-size: 18px;}
}
</style>
</head>
<body>
<div class="sidenav">
About
Services
Clients
Contact
<button class="dropdown-btn">Dropdown
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-container">
Link 1
Link 2
Link 3
<button class="dropdown-btn">Dropdown
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-container">
Link 1
Link 2
Link 3
</div>
</div>
Search
</div>
<div class="main">
<h2>Sidebar Dropdown</h2>
<p>Click on the dropdown button to open the dropdown menu inside the side navigation.</p>
<p>This sidebar is of full height (100%) and always shown.</p>
<p>Some random text..</p>
</div>
<script>
/* Loop through all dropdown buttons to toggle between hiding and showing its dropdown content - This allows the user to have multiple dropdowns without any conflict */
var dropdown = document.getElementsByClassName("dropdown-btn");
var i;
for (i = 0; i < dropdown.length; i++) {
dropdown[i].addEventListener("click", function() {
this.classList.toggle("active");
var dropdownContent = this.nextElementSibling;
if (dropdownContent.style.display === "block") {
dropdownContent.style.display = "none";
} else {
dropdownContent.style.display = "block";
}
});
}
</script>
</body>
</html>

Related

CSS Animation on Sidebar Submenu

I've been trying to figure this out, but I'm honestly lost. I'm making a sidebar that has three levels: a main menu, with two more submenus when you hover over the menu items(so it's main menu item > submenu item > another submenu). The thing is, I'm not very good with CSS animations, but I'm trying to learn. And was wondering if this could be done with it?
Here's my code so far. Initially, I started this out with JS, but stackoverflow told me it'd be easier to do it with CSS animation. And honestly, this looks way cleaner. Anyway, currently, it shows the icon titles beside it when you hover over a sidebar. But how exactly should I go about making the submenu appear when you hover over each menu item separately? Should I do it by having a whole new div appear on hover, or should I do it by expanding the existing one(this doesn't seem like it'd be a good idea)?
What's the correct way? And on which elements should I add CSS transitions to achieve that smooth slidein sidebar?
/* .subnav {
position: fixed;
background-color: red;
margin-top: 0;
top: 75px;
left: 75px;
height: 100vw;
}
my poor attempt at submenu */
.sidebar {
margin-top: 75px;
position: fixed;
width:75px;
height:100vw;
top:0;
left:0;
z-index:100;
background-color: #292a2c;
color: #000;
overflow: hidden;
transition: width .5s;
}
.sidebar:hover {
width: 160px;
}
.sidebar ul {
width:200px;
}
.sidebar a i {
font-size: 30px;
}
.sidebar a {
color:#fff;
font-size:14px;
text-decoration:none;
}
.nav-item {
padding-left: 8px;
}
.nav-item:hover {
background-color: $primary-color;
}
span {
display: none;
font-size: 14px;
}
.sidebar:hover span {
display: initial;
}
<div class="sidebar">
<ul class="nav flex-column m-0">
<li class="nav-item py-2">
<a class="nav-link" href="#">
<i class="fa fa-envelope-open" aria-hidden="true"></i>
<span class="pl-1">
Item
</span>
</a>
<ul class="nav subnav flex-column">
<li class="nav-item">
<a class="nav-link active" href="#">
Overview
<span class="sr-only">
(current)
</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Reports</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Analytics</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Export</a>
</li>
</ul>
</li>
</ul>
</div>
Thank you!
I hope this will help you. Here is some modification in your previous code.
You can also check it on Jsfiddle
*
{
color: #fff;
}
/* .subnav {
position: fixed;
background-color: red;
margin-top: 0;
top: 75px;
left: 75px;
height: 100vw;
}
my poor attempt at submenu */
.sidebar {
margin-top: 75px;
position: fixed;
width:20px;
height:100vw;
top:0;
left:0;
z-index:100;
background-color: #292a2c;
color: #000;
overflow: hidden;
transition: width .5s;
}
.sidebar:hover {
width: 250px;
}
.sidebar ul {
width:200px;
}
.sidebar a i {
font-size: 30px;
}
.sidebar a {
color:#fff;
font-size:14px;
text-decoration:none;
}
.nav-item {
padding-left: 8px;
}
.nav-item:hover {
background-color: $primary-color;
}
span {
display: none;
font-size: 14px;
}
.sidebar:hover span {
display: initial;
}
/* reset our lists to remove bullet points and padding */
.mainmenu, .submenu, .submenu1 {
padding: 0;
margin: 0;
}
/* make ALL links (main and submenu) have padding and background color */
.mainmenu a {
display: block;
text-decoration: none;
padding: 10px;
}
/* add hover behaviour */
.mainmenu a:hover {
background-color: #C5C5C5;
}
.mainmenu li:hover .submenu {
display: block;
max-height: 200px;
}
.submenu li:hover .submenu1 {
display: block;
max-height: 200px;
}
.submenu a
{
}
.submenu li
{
padding-left: 15px;
}
.submenu1 a
{
}
.submenu1 li
{
padding-left: 20px;
}
/* hover behaviour for links inside .submenu */
.submenu a:hover {
background-color: #666;
}
/* this is the initial state of all submenus.
we set it to max-height: 0, and hide the overflowed content.
*/
.submenu,
.submenu1{
overflow: hidden;
max-height: 0;
-webkit-transition: all 0.5s ease-out;
}
<div class="sidebar">
<ul class="nav flex-column m-0">
<li class="nav-item py-2">
<a class="nav-link" href="#">
<i class="fa fa-envelope-open" aria-hidden="true"></i>
<span class="pl-1">Item</span>
</a>
<nav class="navigation">
<ul class="mainmenu">
<li><span class="sr-only"></span>Home</li>
<li>About
<ul class="submenu">
<li>Team</li>
<li>Contact Us
<ul class="submenu1">
<li>Phone</li>
<li>Email</li>
<li>Fax</li>
</ul>
</li>
</ul>
</li>
<li>Our Products</li>
</ul>
</nav> </li>
</ul>
</div>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Multi-Level Drop Down Menu with Pure CSS</title>
<style>
ul {
list-style: none;
padding: 0;
margin: 0;
background: #1bc2a2;
}
ul li {
display: block;
position: relative;
float: left;
background: #1bc2a2;
}
/* This hides the dropdowns */
li ul { display: none; }
ul li a {
display: block;
padding: 1em;
text-decoration: none;
white-space: nowrap;
color: #fff;
}
ul li a:hover { background: #2c3e50; }
/* Display the dropdown */
li:hover > ul {
display: block;
position: absolute;
}
li:hover li { float: none; }
li:hover a { background: #1bc2a2; }
li:hover li a:hover { background: #2c3e50; }
.main-navigation li ul li { border-top: 0; }
/* Displays second level dropdowns to the right of the first level dropdown */
ul ul ul {
left: 100%;
top: 0;
}
/* Simple clearfix */
ul:before,
ul:after {
content: " "; /* 1 */
display: table; /* 2 */
}
ul:after { clear: both; }
</style>
</head>
<body>
<ul class="main-navigation">
<li>Front End Design
<ul>
<li>HTML</li>
<li>CSS
<ul>
<li>Resets</li>
<li>Grids</li>
<li>Frameworks</li>
</ul>
</li>
<li>JavaScript
<ul>
<li>Ajax</li>
<li>jQuery</li>
</ul>
</li>
</ul>
</li>
</ul>
<h1>Multi-Level Drop Down Menu with Pure CSS</h1>
<div class="css-script-ads"><script type="text/javascript"><!--
google_ad_client = "ca-pub-2783044520727903";
/* CSSScript Demo Page */
google_ad_slot = "3025259193";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="//pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-46156385-1', 'cssscript.com');
ga('send', 'pageview');
</script>
</body>
</html>
Hope it helps you. Please check it out and let me know.
Just modified your css a bit. Check if this helps. jsfiddle
.subnav {
position: fixed;
background-color: red;
margin-top: 0;
top: 75px;
left: 75px;
height: 100vw;
opacity:0;
overflow:hidden;
}
.sidebar {
margin-top: 75px;
position: fixed;
width:75px;
height:100vw;
top:0;
left:0;
z-index:100;
background-color: #292a2c;
color: #000;
overflow: hidden;
transition: width .5s;
}
.sidebar:hover {
width: 160px;
}
.sidebar .subnav
{
transform:75px;
transition: transform .5s;
}
.sidebar:hover .subnav{
transform: translateX(85px)
}
.sidebar a i {
font-size: 30px;
}
.sidebar a {
color:#fff;
font-size:14px;
text-decoration:none;
}
.nav-item {
padding-left: 8px;
}
.nav-item:hover {
background-color: $primary-color;
}
span {
display: none;
font-size: 14px;
}
.sidebar:hover span {
display: initial;
}
.nav-item:hover .subnav {
opacity: 1;
}

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>

Bootstrap Navbar overflows and breaks links when overflow is hidden

I have a bootstrap navbar that overflows on mobile, when I set my css to hide the overflow, the button links break. I am at a total loss. Here is my navbar code. Here is a link to the site. I would love if anyone has the opportunity to help thanks.
HTML
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<button id="btnCollapse" 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>
<h1 class="navbar-brand">Goode Development</h1>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav navbar-left">
<li><a class="a" href="#homey">Home</a></li>
<li><a class="a" href="#porty">Portfolio</a></li>
<li><a class="a" href="#abouty">About</a></li>
<li><a class="a" href="#conty">Contact</a></li>
</ul>
</div>
</div>
</nav>
CSS
.navbar {
height: 125px;
background-color:#0d0d0d !important;
}
.navbar-brand {
position: relative!important;
left: 45px!important;
bottom: 10px!important;
font-size: 4em!important;
color: white!important;
font-family: "Montserrat", sans-serif !important;
white-space:nowrap;
}
.nav.navbar-nav.navbar-left li a {
color: white;
position: relative;
right: 475px;
top: 66px;
font-family: "Montserrat", sans-serif !important;
}
.nav.navbar-nav.navbar-left li a:hover {
color: orange;
}
#myNavbar {
background-color: #0d0d0d ;
}
#media screen and (max-width: 990px) {
.navbar-header {
float: none !important;
}
.navbar-brand {
left: 0 !important;
}
.nav li a {
padding: 5px;
margin-right: 50px;
}
.nav.navbar-nav.navbar-left li a {
color: white;
right: 0px;
top: 0px;
}
}
#media screen and (max-width: 767px) {
.navbar-brand {
font-size: 40px !important;
position: relative !important;
top: -20px !important;
left: -10px !important;
}
.navbar {
height: 70px;
}
.nav.navbar-nav.navbar-left li a {
color: #0d0d0d;
right: 0;
top: 0;
}
.navbar-collapse{
overflow-x:hidden;
}
.collapsing,
.in {
background-color: #222222;
position: relative;
top: -30px;
}
.collapsing ul li a,
.in ul li a {
color: white!important;
}
.collapsing ul li a:hover,
.in ul li a:hover {
color: orange!important;
}
}
You need to adjust you're viewport meta tag for flawless responsive display.
You're currently having:
<meta name="viewport" content="width=device-width, initial-scale=1">
Adding of minimum, maximum scale, and the user scalability to the meta tag will fix your problem.
Try this:
<meta name="viewport" content="initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=0,width=device-width" />

bootstrap collapse menu has 2 rows

I am building this website
torgoborudovanie.com
I have a collapsing navbar build with bootstrap.But when I try to resize the window I get something like this :
As you can see (and you can actually try it ) nav bar now has 2 lines and it looks wired (the actual problem is that it looks like this on Iphone and Ipad) Then you can resize it a little bit more and it gets collapsed as I want.
You can see the code by simply viewing html code in developer tools.
So I will not post it here to make qustion clean and small.But if you want I can post the code here too=)
I ended up with this (quite shitty to be fair workaround)
On page load if I have window.width less than 1200px I just hide long text.
function hideSlogan() {
if($(window).width() <1200) {$('.slogan').hide()}
};
hideSlogan();
Go to the CSS rules starting at the MOBILE NAV comment; these are the rules you can adjust to make the navbar collapse at different breakpoints.
On a sidenote, there is one extra, broken list tag in the nav and with the positioning of Надежный партнер - качественные решения! inside your navbar-collapse div you'll the following behavior:
If you expand the menu when it's in the mobile and then expand the viewport your navbar will revert to the line-height: 60px unless the browser is refreshed. Might not matter but since you're trying to change the collapse breakpoint it's worth mentioning.
**I also moved the inline styles with the rest of the CSS Rules.
#import url(http://fonts.googleapis.com/css?family=Open+Sans:400, 700, 800);
#import url(http://fonts.googleapis.com/css?family=Libre+Baskerville:400italic);
* {
margin: 0;
padding: 0px;
font-family: 'Open Sans', sans-serif;
}
body {
background: #fff;
margin: 0;
color: #42413e;
padding-top: 50px;
}
/* BOOTSTRAP MODIFICATION */
.navbar-right a .btn-orange {
margin-top: -5px;
}
.btn-orange {
background: #f27242;
border-radius: 2px;
color: white;
font-size: 12px;
font-weight: 700;
}
.btn-orange:hover {
background: #e16a3e;
color: white;
}
.navbar-default .navbar-brand {
height: 50px;
padding: 10px 15px;
font-size: 20px;
line-height: 22px;
font-weight: 700;
}
.navbar.navbar-default {
background-color: #ffffff;
border-color: #e7e7e7;
}
.navbar-default .navbar-nav > .active > a,
.navbar-default .navbar-nav > .active > a:hover,
.navbar-default .navbar-nav > .active > a:focus {
color: #f27242;
background-color: transparent;
}
.navbar-default .navbar-nav > li > a {
color: #ccc;
}
.navbar-default .navbar-right {
padding-top: 5px
}
.navbar-default li.dropdown a {
color: black;
}
.navbar-default span.head-title {
line-height: 60px;
}
.navbar-default .navbar-right .dropdown-menu {
right: auto;
left: 0;
}
.navbar-right li.contact-info a {
color: #42413e;
}
/****MOBILE NAVBAR******/
#media (max-width: 1200px) {
.custom-navbar .navbar-header {
float: none;
}
.custom-navbar .navbar-left,
.custom-navbar .navbar-right {
float: none !important;
}
.custom-navbar .navbar-toggle {
display: block;
}
.custom-navbar .navbar-collapse {
border-top: 1px solid transparent;
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1);
overflow-x: hidden;
}
.custom-navbar.navbar-fixed-top {
top: 0;
border-width: 0 0 1px;
}
.custom-navbar .navbar-collapse.collapse {
display: none!important;
}
.custom-navbar .navbar-nav {
float: none!important;
margin-top: 7.5px;
}
.custom-navbar .navbar-nav > li {
float: none;
}
.custom-navbar .navbar-nav > li > a {
padding-top: 10px;
padding-bottom: 10px;
}
.custom-navbar .collapse.in {
display: block !important;
}
.custom-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;
}
.custom-navbar .navbar-brand {
height: 55px;
padding: 10px 15px;
font-size: 20px;
line-height: 22px;
font-weight: 700;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css" rel="stylesheet" />
<nav class="navbar navbar-default custom-navbar navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"> <span class="sr-only">Переключить навигацию</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">
<img src="http://www.torgoborudovanie.com/assets/img/logo1.png" width="140">
</a>
</div>
<div class="collapse navbar-collapse"><span class="head-title">Надежный партнер - качественные решения!</span>
<ul class="nav navbar-nav navbar-right">
<li class="dropdown"> Каталог <span class="caret"></span>
<ul class="dropdown-menu">
<li>Стеллажи
</li>
<li>Торговая мебель
</li>
<li>Тележки и корзины
</li>
<li> Кассовые боксы
</li>
<li>Холодильное оборудование
</li>
<li role="separator" class="divider"></li>
<li>Условия доставки
</li>
</ul>
</li>
<li class="contact-info">
<i class="fa fa-phone "></i> 8 (343) 3448090
</li>
<li class="contact-info">
<i class="fa fa-envelope"></i> info#optimagp.ru
</li>
<li>
<a href="#f">
<button class="btn btn-sm btn-orange" type="button">Заказать звонок</button>
</a>
</li>
</ul>
</div>
</div>
</nav>
you need to change your breakpoint, when the navbar gets collapsed...
so for example, this should work:
#media only screen and (min-width: 1200px) {
.collapse {
display: block;
}
.navbar-toggle {
display: none;
}
}
#media only screen and (max-width: 1200px) {
.collapse {
display: none;
}
.navbar-toggle {
display: block;
}
}
because it floats (because its so long) after 1200px width...
** sorry, i made a mistake... try it now :) **

How to make responsive navbar?

Here is my navbar:
<nav class="navbar navbar-default">
<div class="container-fluid">
<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>
<a class="navbar-brand" href="/"><img src="/img/logo.png"></a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="active">LONG<br>ITEM1</li>
<li>LONG<br>ITEM 2</li>
<li>LONG<br>ITEM 3</li>
<li>LONG<br>ITEM 4</li>
<li>LONG<br>ITEM 5</li>
</ul>
</div>
</div>
</nav>
and css:
.navbar {
min-height: 100px;
font-family: 'Roboto Condensed', sans-serif;
font-size: 25px;
margin-bottom: 0px;
padding: 0px 70px;
}
.navbar-brand>img {
height: 70px;
}
.navbar-brand {
padding-top: 15px;
padding-bottom: 15px;
}
.navbar-default {
background: #5aa0d1;
border-radius: 0;
-webkit-box-shadow: none;
-box-shadow: none;
border: 0;
}
.navbar-default .navbar-brand {
color: #fff14f;
}
.navbar-default .navbar-nav > li > a {
color: #fff14f;
line-height: 24px;
padding-top: 28px;
}
.navbar-default .navbar-nav>li.active>a {
color: #ffffff;
background-color: transparent;
}
.navbar-default .navbar-nav>.active>a, .navbar-default .navbar-nav>.active>a:focus, .navbar-default .navbar-nav>.active>a:hover {
color: #ffffff;
background-color: transparent;
}
.navbar-default .navbar-nav>li>a:focus, .navbar-default .navbar-nav>li>a:hover {
color: #ffffff;
}
It doesn't displayed well on small devices (iPad, iPhone, Android devices) - some navbar elements overlay others (see real example at vkko.ru).
What is wrong there? How should I fix that?
I can see two issues here since you are not specifying what exactly you want fixed.
The logo is too big for an xs screen and the divider overlays the logo when you open the burger menu. I noticed you are using an image for a logo hence you don't really need to use the navbar-brand since that class adds unnecessary css for text based logos, you can simply use pull-left class.
<a class="pull-left" href="/"><img src="/img/logo.png"></a>
The other one is the font-size is too large and hence pushes the list of links to the next line when on smaller devices. You can use "media queries" to detect when a user is on a smaller device and adjust the font-size accordingly and I have used the css solution from this answer to fix your issue.
I have made a pen to help you visualise everything mentioned above. Hope it helps. http://codepen.io/anon/pen/PqEmgP
I've created a responsive navbar using only CSS,JS and JQuery. No additional library/plugins required.
Added animation on close, open navbar on mobile view.
Added animated hamburger menu.
You can checkout the demo+code here: https://codepen.io/jerrygoyal/pen/XEZvgG
HTML:
<nav class="navbar-menu">
<a class="nav-homepage">
JerryGoyal
</a>
<div class="nav-menu-select">
<a class="nav-hamburger">
<div class="hamburger bar1"></div>
<div class="hamburger bar2"></div>
<div class="hamburger bar3"></div>
</a>
</div>
<ul class="nav-menu-options">
<li>
<a>Apps</a>
</li>
<li>
<a>About Me</a>
</li>
<li>
<a>Contact</a>
</li>
</ul>
</nav>
JS:
$(document).ready(function () {
initNavbar();
});
function initNavbar(){
// 0 = hide, 1 = visible
var menuState = 0;
/* Add a Click event listener to btn-select */
$(".nav-hamburger").on("click",function() {
$(this).toggleClass('change');
if(menuState === 0) {
$(".nav-menu-options").slideDown("slow");
menuState = 1;
} else {
$(".nav-menu-options").slideUp("slow");
menuState = 0;
}
});
}
CSS:
/*****************************************************
NAV BAR START
*****************************************************/
.navbar-menu {
background-color: #005ec8;
width: calc(100%);
height: 55px;
}
.navbar-menu a{
color: #ffffff;
text-decoration: none;
font-size: 17px;
cursor: pointer;
}
.navbar-menu a:hover {
background-color: #fff;
color: #005ec8;
}
.nav-menu-options li a {
display: block;
padding: 18px;
}
.nav-homepage{
display: inline-block;
font-weight: bold;
font-size: 20px !important;
letter-spacing: 1px;
position: absolute;
z-index: 1;
padding: 17px;
}
.nav-menu-select {
margin: 0;
text-align: right;
height: inherit;
}
.nav-hamburger{
display: inline-block;
padding: 13px;
}
.nav-menu-options {
display: block;
text-align: right;
width: 100%;
margin: 0px;
padding: 0px;
background-color: inherit;
}
/* DESKTOP */
#media screen and (min-width: 750px) {
.nav-menu-select{
display: none;
}
.nav-menu-options{
display: block !important;
border-bottom: 0;
}
.nav-menu-options li{
display: inline-block;
}
}
/* MOBILE */
#media screen and (max-width: 750px) {
.navbar-menu {
margin: 0;
}
.nav-menu-options {
display: none;
position: relative;
text-align: center;
}
.nav-menu-options li{
display: block;
}
}
.hamburger {
width: 25px;
height: 2px;
background-color: currentColor;
margin: 6px 0;
transition: 0.4s;
}
.nav-hamburger:before{
content: "";
position: absolute;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
width: 40px;
height: 40px;
border: 2px solid transparent;
top: 8px;
right: 4px;
border-radius: 100%;
-webkit-transition: all 0.4s ease-in-out;
-o-transition: all 0.4s ease-in-out;
transition: all 0.4s ease-in-out;
z-index: 1;
}
.nav-hamburger.change:before{
border: 2px solid currentColor;
}
.change .bar1 {
-webkit-transform: rotate(-45deg) translate(-4px, 7px);
transform: rotate(-45deg) translate(-4px, 7px);
}
.change .bar2 {opacity: 0;}
.change .bar3 {
-webkit-transform: rotate(45deg) translate(-4px, -7px);
transform: rotate(45deg) translate(-4px, -7px);
}
/*****************************************************
NAV BAR END
*****************************************************/
body{
background-color:#ffa700;
margin:0
}
you can use something like this:
#media screen and (max-width: 1024px) {}
and set custom rules for custom devices, I know its more of hardwork and not smartwork but it's more precise and trustable than using vw or vh
I made a responsive navbar with dropdown menu interactive with content.
if interested you can check it out!
https://youtu.be/0yF6ulcW7h0