Dropdown menu collapses inside the navbar when screen is smaller - css

Click here for the view
As you can see, I'm having problem with the dropdown. It works fine when screen is bigger than 768px (which is the width I set on the media query) but when the screen width is now equal or less than 768px, the dropdown menu does not shows outside the navigation instead it collapses inside the navigation bar. Please look at the picture to see what happens.
I already tried z-index, position property etc, but not one works.
How can I make the dropdown menu show outside of the navigation bar instead of collapsing inside it?
Here is my HTML for nav:
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<a id="sidebarCollapse" href="#" data-toggle="offcanvas"><i class="fa fa-navicon fa-2x"></i></a>
</div>
<div id="navbar-right">
<ul class="nav navbar-nav navbar-right">
<li>Logout 2</li>
<li>
<div class="dropdown">
<button class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown">Dropdown Example
<span class="caret"></span></button>
<ul class="dropdown-menu">
<li>HTML</li>
<li>CSS</li>
<li>JavaScript</li>
</ul>
</div>
</li>
</ul>
</div>
</div>
</nav>
Here's the CSS, I only included the CSS on the media query since there's no problem on the screen size except when it reach 768px or below. Also the view on the picture has no CSS for the dropdown, so it's the actual dropdown without any styling:
#media (max-width: 768px) {
#sidebar {
margin-left: -250px;
}
#sidebar.active {
margin-left: 0;
}
#content {
width: 100%;
}
#content.active {
width: calc(100% - 250px);
}
.container-fluid {
display: inline-flex;
overflow: hidden;
width: 100%;
height: 100%;
position: absolute;
padding: 0;
margin: 0;
}
.container-fluid #navbar-right {
width: 100%;
}
.container-fluid ul {
display: inline-flex;
float: right;
}
ul.nav {
height: 100%;
margin: 0;
}
.navbar {
padding: 0;
margin: 0;
}
.navbar-header a i {
margin-left: 15px;
}
.navbar-right li a {
height: 100%;
line-height: 30px;
}
/****/
ul.dropdown-menu {
}
}

Remove the overflow hidden from the container-fluid class:
.container-fluid {
display: inline-flex;
width: 100%;
height: 100%;
position: absolute;
padding: 0;
margin: 0;
}
Add the overflow:hidden to the dropdown class:
.dropdown {
overflow:hidden;
}
Codepen link: https://codepen.io/anon/pen/mpEjXq?editors=1100

Related

Footer appears mid-screen

I know there are duplicates of similar questions to this but I just can't get my footer to stay at the bottom, and I've tried multiple suggested fixes. Please show me how to move the footer to the bottom of the page. Does it have something to do with the body? Whoever posts a solution could you say what it was that was incorrect?
<head>
<meta charset="utf-8">
<title>CopperMug</title>
<link href="Coppermug Stylesheet.css" rel="stylesheet" type="text/css">
</head>
<div class="navbar" id="navbarSupportedContent">
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Services</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">About Us</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Contact</a>
</li>
</div>
<body id="body">
<div>
<img src="../Final Logo Assets/Coppermug banner no background 2-min.png" class="img" id="logo">
</div>
</body>
<footer>
<a class="service-link" href="#">Privacy Policy</a>
<a class="service-link" href="#">Terms of Service</a>
</footer>
</html>
#charset "utf-8";
/* CSS Document */
html {
background-image: url("../Final Logo Assets/Blur Mug-min Opacity-min.jpg");
background-repeat: no-repeat;
background-size: cover;
}
#body {
}
#header,
li .nav-link {
font-family: "Copperplate Gothic";
color: #000000
}
#logo { display: block;
margin-left: 26%;
margin-right: auto;
margin-top: 12%;
width: 50%;}
#navbarSupportedContent {
color: black;
font-family: "Copperplate Gothic";
font-size: .99em;
padding: 1em;
}
#navbarSupportedContent li {
list-style-type: none;
display: inline-block;
}
div #navbarSupportedContent {
width: 100%;
}
.navbar {
text-align: center;
position: relative;
font-size: 150%;
margin-left: 3%;
}
.navbar-nav {
text-align: center;
position: relative;
font-size: 150%;
}
footer .service-link {
color: #000000;
}
footer {
text-align: center;
clear: both;
position: relative;
height: 40px;
margin-top: -40px;
}
What you have currently is a footer element which exists as just another plain element in the page flow (FYI, you have a redundant position:relative on it), so where it ends up is wherever the content above it ends (ie your image).
If you want a footer slammed to the bottom of the viewport that always remains visible regardless of content length or scroll position, then you'd use position: fixed on your footer, as crodev's answer shows. However this takes up screen real estate and is used with intention and good reason (like some action bar during some kind of funneled user experience).
However, for regular page circumstances, when you have short content, and want the footer to appear at the bottom of the viewport, it's best using a flex layout like below (which offers all kinds of advantages as well):
Codepen
body {
height: 100vh;
margin: 0;
}
#container {
display: flex;
flex-direction: column;
justify-content: space-between;
height: 100%;
}
#header {
background-color: red;
min-height: 100px;
}
#content {
flex: 1;
background-color: green;
/* to test a longer page */
/* min-height: 3000px; */
}
#footer {
background-color: blue;
min-height: 100px;
}
.section {
padding: 1em;
display: flex;
justify-content: center;
align-items: center;
}
<div id="container">
<div id="header" class="section">
header
</div>
<div id="content" class="section">
content
</div>
<div id="footer" class="section">
footer
</div>
</div>
HTML:
<div class="footer">
<p>Footer</p>
</div>
CSS:
.footer {
position: fixed;
left: 0;
bottom: 0;
width: 100%;
background-color: transparent;
color: white;
text-align: center;
}

Is it possible to combine an Off-canvas menu with modal function using Jasny Bootstrap?

I'm having trouble combining off-canvas with modal functionality using Jasny Bootstrap
These are the steps I took:
1. I created an off-canvas menu using jasny bootstrap, and it works as intended Off Canvas Only
2. However, when I add the modal functionality, it makes the off-canvas menu disappear after stretching the screen to 992px width. Also I can't close the modal by clicking outside of the element. Modal functionality + Off-Canvas
The problem I have is with the data-toggle="modal" or data-toggle="offcanvas" I can only use one or the other. Is there another way to add two data toggles?
Or better yet:
What options do I have to use both an offcanvas menu with modal functionality?
Pre-Requisites:
Bootstrap.min.css
Bootstrap.min.js
jasny-bootstrap.css
jasny-bootstrap.js
HTML
<div id="myModal" class="modal fade navmenu navmenu-default navmenu-fixed-left offcanvas-sm">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<a class="navmenu-brand visible-md visible-lg visible-sm visible-xs" href="#">Chronicles</a>
<ul class="nav navmenu-nav">
<li class="active"><a class="nav-link" href="index.html">Slide in</a></li>
<li><a class="nav-link" href="http://www.jasny.net/bootstrap/examples/navmenu-push/">Push</a></li>
<li><a class="nav-link" href="http://www.jasny.net/bootstrap/examples/navmenu-reveal/">Reveal</a></li>
<li><a class="nav-link" href="http://www.jasny.net/bootstrap/examples/navbar-offcanvas/">Off canvas navbar</a></li>
</ul>
</div>
<div class="navbar navbar-default navbar-fixed-top hidden-md hidden-lg navbar-preheader">
<button type="button" class="navbar-toggle" data-toggle="modal" data-target=".navmenu, #myModal">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Project name</a>
</div>
<div class="container">
<div class="page-header">
<h1>Navmenu Template</h1>
</div>
<p class="lead">This example shows the navmenu element. If the viewport is <b>less than 992px</b> the menu will be placed the off canvas and will be shown with a slide in effect.</p>
</div><!-- /.container -->
CSS:
html, body {
height: 100%;
}
body {
padding: 50px 0 0 0;
}
.navmenu-fixed-left {
z-index:1050;
top: 0;
bottom: 0; background:#fff!important;
}
.navbar-fixed-top {
background:#fff!important;
}
.navbar {
display: block;
text-align: center;
}
.navbar-brand {
display: inline-block;
float: none;
}
.navbar-toggle {
position: absolute;
float: left;
margin-left: 15px;
}
.container {
max-width: 100%;
}
#media (min-width: 1px) {
.navbar-toggle {
display: block !important; background:none!important; border:none !important; color:#f90 !important;
}
}
#media (min-width: 992px) {
body {
padding: 0 0 0 300px;
}
.navmenu {
padding-top: 0;
}
.navbar {
display: none !important; /* IE8 fix */
}
}
.navbar-default .navbar-toggle .icon-bar{
background-color:#f90;
}
.modal-body {
max-height: calc(100vh - 210px);
overflow-y: auto;
}
::-webkit-scrollbar {
width: 12px;
}
::-webkit-scrollbar-track {
-webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3);
border-radius: 10px;
}
::-webkit-scrollbar-thumb {
border-radius: 10px;
-webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.5);
}
No, modal and offcanvas should not be used on the same element. Unexpected things will happen.
If you simply want to add a backdrop with offcanvas, better add that manually rather than using the modal plugin.
In the HTML add
<div class="backdrop">
With CSS
.backdrop {
background: rgba(0, 0, 0, 0.5);
position: fixed;
top: 0;
bottom: 0;
width: 100vw;
height: 100vh;
z-index: 1040;
display: none;
}
Than using JavaScript, show and hide the backdrop
$('.navmenu').on('show.bs.offcanvas', function() {
$('.backdrop').fadeIn();
});
$('.navmenu').on('hide.bs.offcanvas', function() {
$('.backdrop').fadeOut();
});
Last, adding a close button to the menu is trivial
×
See the fiddle

CSS keep menu in container and expand background to full screen

The picture below shows what I would like to get.
It is a menu within a container, where the menu may wrap to multiple lines when the window/screen gets too narrow for all menu items to fit in. At the same time I would like the menu to have a background which expands to full screen in width, while expanding in height with the menu when it gets wrapped to multiple lines. Currently I think this is not possible with CSS, but I am also just a CSS amateur. My current solution involves #media queries to set the height of the menu background for resolutions where wrapping appears. This does not take into account that font-size could change, thus making each line of menu higher.
Here is a jsFiddle with a basic setup, which does NOT what I want:
https://jsfiddle.net/n3jmyq2f/3/ (Edited, was not the final version)
Here is the code:
<div class="container">
<div class="menu_wrap">
<div class="menu_bg"></div>
<div class="menu">
<ul>
<li>item 1</li>
<li>item2</li>
<li>item3</li>
<li>item4</li>
<li>item5</li>
<li>item6</li>
</ul>
</div>
</div>
<div class="content">It's me, Mario!</div>
CSS:
.container {
width:50%;
margin: 0 auto;
background:lightgreen;
height:300px;
}
.menu_bg{
position: absolute;
background: #afafaf;
width: 100%;
left:0;
height:30px;
z-index: -1;
}
ul {
height:30px;
background: #afafaf;
}
li {
display:inline-block;
}
The first option is the simplest.
Stop thinking of the .container as something that must contain everything. It's just a class that can be reused as and when required.
If you take the menu div out of the "container" but put a .container div inside you get the effect you are looking for.
JSfiddle Demo
*,
body {
padding: 0;
margin: 0;
}
.container {
width: 50%;
margin: 0 auto;
background: lightgreen;
}
.menu {
background: #afafaf;
}
ul {
border: 1px solid green;
}
li {
display: inline-block;
}
.content {
height: 300px;
}
<div class="menu">
<div class="container">
<ul>
<li>item 1
</li>
<li>item2
</li>
<li>item3
</li>
<li>item4
</li>
<li>item5
</li>
<li>item6
</li>
</ul>
</div>
</div>
<div class="container">
<div class="content">It's me, Mario!</div>
</div>
2nd Option
Use a pseudo-element
*,
body {
margin: 0;
padding: 0;
}
.container {
width: 50%;
margin: 0 auto;
background: lightgreen;
height: 300px;
}
ul {
background: #afafaf;
position: relative;
border: 1px solid green;
}
ul:before {
content: '';
position: absolute;
height: 100%;
background: inherit;
width: 100vw;
left: 50%;
transform: translateX(-50%);
z-index: -1
}
li {
display: inline-block;
}
<div class="container">
<div class="menu">
<ul>
<li>item 1
</li>
<li>item2
</li>
<li>item3
</li>
<li>item4
</li>
<li>item5
</li>
<li>item6
</li>
</ul>
</div>
<div class="content">It's me, Mario!</div>
</div>
JSfiddle Demo
if in .container you change
width:50%;
to
width:100%;
it will do it
fiddle
you could also use the .menu-wrap class (which I've seen in your markup) to do this

Material Design: Bootstrap 3 Responsive Navbar

Current code: http://www.bootply.com/NuuxNSnmrf
I have a few issues I am struggling with in this revision:
hamburger icon is not on the left side upon collapse
vertical gap between left and right side text
brand is not centered
My goal:
Suggestions appreciated!
Update like this along with your code: Demo
.navbar-toggle {
float: left;
}
.navbar-brand {
display: block;
float: none;
text-align: center;
}
.navbar-nav > li > a {
padding-bottom: 3px;
padding-top: 3px;
}
I wrote my own minimal bootstrap navbar stylesheet which builds on top of Bootstrap variables.
/* material navbar */
.material-navbar {
/*
Hides normally visible elements
important notes:
#grid-float-breakpoint - point at which navbar becomes uncollapsed
#grid-float-breakpoint-max - point at which the navbar begins collapsing
*/
> * {
width: 100%;
flex: 1;
list-style-type: none;
}
> .left {
text-align: left;
}
> .center {
text-align: center;
}
> .right {
text-align: right;
}
padding: #navbar-padding-vertical #navbar-padding-horizontal;
margin: 0;
/* collapsed */
#media (max-width: #screen-sm-max) {
display: none;
}
/* not collapsed */
#media (min-width: (#screen-sm-max - 1px)) {
display: flex;
flex-direction: row;
align-items: baseline;
align-content: center;
flex-wrap: nowrap;
justify-content: space-between;
}
}
.material-navbar-collapsed {
/*
Shows normally visible elements
important notes:
#grid-float-breakpoint - point at which navbar becomes uncollapsed
#grid-float-breakpoint-max - point at which the navbar begins collapsing
*/
> * {
width: 100%;
flex: 1;
list-style-type: none;
}
> .left {
text-align: left;
}
> .center {
text-align: center;
}
> .right {
text-align: right;
}
padding: #navbar-padding-vertical #navbar-padding-horizontal;
margin: 0;
/* collapsed */
#media (max-width: #screen-sm-max) {
display: flex;
flex-direction: row;
align-items: baseline;
align-content: center;
flex-wrap: nowrap;
justify-content: space-between;
}
/* not collapsed */
#media (min-width: (#screen-sm-max - 1px)) {
display: none;
}
}
Example:
https://jsfiddle.net/eo2gsxcm/
Update 1: https://jsfiddle.net/eo2gsxcm/1/
Update 2:
Set viewport breakpoints to screen-sm-max https://jsfiddle.net/eo2gsxcm/2/
What I have changed:
included expanded left & rigt navbar toggle buttons inside the navbar-header div and got rid of the container div on left-navbar-menu & right-navbar-menu unordered list elements.
applied float:left on the hamburger menu
aligned left navbar and right navbar list item text to left and right respectively.
included as third dummy search button.
.navbar-brand {
position: absolute;
width: 100%;
left: 0;
top: 0;
text-align: center;
color: #FFFFFF;
margin: auto;
}
.navbar {
background-color: #3F50B5;
color: #FFFFFF;
}
a {
color: #FFFFFF !important;
}
a:hover {
color: #000000 !important;
}
.custom-navbar .hamburger-on-left {
float: left;
}
.navbar-left li {
text-align: left;
}
.navbar-right li {
text-align: right;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet" />
<nav class="navbar navbar-fixed-top custom-navbar" role="navigation">
<div class="container-fluid">
<!-- expanded behavior -->
<div class="navbar-header">
<a class="navbar-brand" href="#">Brand</a>
<!-- expanded left navbar-->
<div class="navbar-left">
<button type="button" class="navbar-toggle hamburger-on-left" data-toggle="collapse" data-target="#left-navbar-menu">
<span class="glyphicon glyphicon-menu-hamburger" aria-hidden="false"></span>
</button>
</div>
<!-- expanded right navbar -->
<div class="navbar-right">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#right-navbar-menu">
<span class="glyphicon glyphicon-option-vertical" aria-hidden="false"></span>
</button>
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#">
<span class="glyphicon glyphicon-search" aria-hidden="false"></span>
</button>
</div>
</div>
<!-- collapsed behavior -->
<ul id="left-navbar-menu" class="nav navbar-nav navbar-left navbar-collapse collapse">
<li>Left
</li>
<li>Left
</li>
</ul>
<ul id="right-navbar-menu" class="nav navbar-nav navbar-right navbar-collapse collapse">
<li>Right
</li>
<li>Right
</li>
</ul>
</div>
</nav>
<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.4/js/bootstrap.min.js"></script>

Spanning div over width remaining next to unordered list?

<div class="nav">
<ul class="nav">
<a class="nav" href="#">
<li class="nav">item1</li>
</a>
<a class="nav" href="#">
<li class="nav">item2</li>
</a>
<a class="nav" href="#">
<li class="nav">item3</li>
</a>
</ul>
<div class="line"></div>
</div>
This is my HTML navbar
CSS:
ul.nav {
display: inline-block;
font-size: 0;
}
li.nav {
display:inline-block;
border-bottom: 2px solid gray;
padding: 15px 20px;
text-align: center;
font-size: 16px;
}
div.nav {
width: 100%;
display: inline-block;
}
How do I style the div.line so it is exactly next to the list (right), fills the rest of the page (width) and has the same height as the ul.nav/div.nav?
Thanks,
First of all, sorry about the english level!
You can do something like:
.line {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: gray;
}
e.g: http://jsfiddle.net/X8fE4/
That's basically turn the div.line into an absolute alement behind your navigation. It will have the width of the parent div.nav, it's not a beautiful solution, but is well supported :)
this might help you:
preview: http://jsfiddle.net/webcarvers/7uZgW/3/embedded/result/
code: http://jsfiddle.net/webcarvers/7uZgW/3/
JS:
$(document).ready(function(){
$("div.two").css({
//-2 is for border width
"width": ($(window).width() - $("div.nav").outerWidth() - 2) + "px",
"height": ($("div.nav").height()-2) + "px"
});
});
div.nav {
display: flex;
display: ms-flex;
display: -webkit-flex;
{
Edit: You also need to add the property flex-grow to .line.
.line {
flex-grow: 1;
}
http://jsfiddle.net/eWHnU/

Resources