Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I am building a browser-based mobile app and I've decided to use Bootstrap 3 as the css framework for the design. Bootstrap 3 comes with a great "responsive" feature in the navigation bar where it collapses automatically if it detects a specific "break point" regarding the resolution of the browser. It works in a lot of situations.
But have you noticed lately how a lot of browser-based mobile apps have the primary navigation hidden out of the left of the screen, and when the toggle icon is pressed (toggled) in the top-right corner, the primary navigation slides out to the right about 2/3 of the way into the screen? This is an increasingly popular solution for navigating through browser-based apps on mobile devices and I think in theory it should be pretty easy to modify bootstrap css/js to accommodate this version of the navigation collapse feature.
How can these feature be implemented? It seems like it shouldn't take too much modification. I'd really like to hear your thoughts/solutions on this matter. Also, I think it would be a great long-term solution for Bootstrap to implement as a built-in feature.
Unfortunately I have not made any attempts to create this feature because while I am familiar with these technologies, I am predominantly a PHP/MySQL developer and I believe a feature as useful as this should be built by experts with insight that I don't have as a front-end developer.
This was for my own project and I'm sharing it here too.
DEMO: http://jsbin.com/OjOTIGaP/1/edit
This one had trouble after 3.2, so the one below may work better for you:
https://jsbin.com/seqola/2/edit --- BETTER VERSION, slightly
CSS
/* adjust body when menu is open */
body.slide-active {
overflow-x: hidden
}
/*first child of #page-content so it doesn't shift around*/
.no-margin-top {
margin-top: 0px!important
}
/*wrap the entire page content but not nav inside this div if not a fixed top, don't add any top padding */
#page-content {
position: relative;
padding-top: 70px;
left: 0;
}
#page-content.slide-active {
padding-top: 0
}
/* put toggle bars on the left :: not using button */
#slide-nav .navbar-toggle {
cursor: pointer;
position: relative;
line-height: 0;
float: left;
margin: 0;
width: 30px;
height: 40px;
padding: 10px 0 0 0;
border: 0;
background: transparent;
}
/* icon bar prettyup - optional */
#slide-nav .navbar-toggle > .icon-bar {
width: 100%;
display: block;
height: 3px;
margin: 5px 0 0 0;
}
#slide-nav .navbar-toggle.slide-active .icon-bar {
background: orange
}
.navbar-header {
position: relative
}
/* un fix the navbar when active so that all the menu items are accessible */
.navbar.navbar-fixed-top.slide-active {
position: relative
}
/* screw writing importants and shit, just stick it in max width since these classes are not shared between sizes */
#media (max-width:767px) {
#slide-nav .container {
margin: 0;
padding: 0!important;
}
#slide-nav .navbar-header {
margin: 0 auto;
padding: 0 15px;
}
#slide-nav .navbar.slide-active {
position: absolute;
width: 80%;
top: -1px;
z-index: 1000;
}
#slide-nav #slidemenu {
background: #f7f7f7;
left: -100%;
width: 80%;
min-width: 0;
position: absolute;
padding-left: 0;
z-index: 2;
top: -8px;
margin: 0;
}
#slide-nav #slidemenu .navbar-nav {
min-width: 0;
width: 100%;
margin: 0;
}
#slide-nav #slidemenu .navbar-nav .dropdown-menu li a {
min-width: 0;
width: 80%;
white-space: normal;
}
#slide-nav {
border-top: 0
}
#slide-nav.navbar-inverse #slidemenu {
background: #333
}
/* this is behind the navigation but the navigation is not inside it so that the navigation is accessible and scrolls*/
#slide-nav #navbar-height-col {
position: fixed;
top: 0;
height: 100%;
width: 80%;
left: -80%;
background: #eee;
}
#slide-nav.navbar-inverse #navbar-height-col {
background: #333;
z-index: 1;
border: 0;
}
#slide-nav .navbar-form {
width: 100%;
margin: 8px 0;
text-align: center;
overflow: hidden;
/*fast clearfixer*/
}
#slide-nav .navbar-form .form-control {
text-align: center
}
#slide-nav .navbar-form .btn {
width: 100%
}
}
#media (min-width:768px) {
#page-content {
left: 0!important
}
.navbar.navbar-fixed-top.slide-active {
position: fixed
}
.navbar-header {
left: 0!important
}
}
HTML
<div class="navbar navbar-inverse navbar-fixed-top" role="navigation" id="slide-nav">
<div class="container">
<div class="navbar-header">
<a class="navbar-toggle">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<a class="navbar-brand" href="#">Project name</a>
</div>
<div id="slidemenu">
<form class="navbar-form navbar-right" role="form">
<div class="form-group">
<input type="search" placeholder="search" class="form-control">
</div>
<button type="submit" class="btn btn-primary">Search</button>
</form>
<ul class="nav navbar-nav">
<li class="active">Home</li>
<li>About</li>
<li>Contact</li>
<li class="dropdown"> Dropdown <b class="caret"></b>
<ul class="dropdown-menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li class="divider"></li>
<li class="dropdown-header">Nav header</li>
<li>Separated link</li>
<li>One more separated link</li>
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li class="divider"></li>
<li class="dropdown-header">Nav header</li>
<li>Separated link</li>
<li>One more separated link</li>
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li class="divider"></li>
<li class="dropdown-header">Nav header</li>
<li>Separated link test long title goes here</li>
<li>One more separated link</li>
</ul>
</li>
</ul>
</div>
</div>
</div>
jQuery
$(document).ready(function () {
//stick in the fixed 100% height behind the navbar but don't wrap it
$('#slide-nav.navbar .container').append($('<div id="navbar-height-col"></div>'));
// Enter your ids or classes
var toggler = '.navbar-toggle';
var pagewrapper = '#page-content';
var navigationwrapper = '.navbar-header';
var menuwidth = '100%'; // the menu inside the slide menu itself
var slidewidth = '80%';
var menuneg = '-100%';
var slideneg = '-80%';
$("#slide-nav").on("click", toggler, function (e) {
var selected = $(this).hasClass('slide-active');
$('#slidemenu').stop().animate({
left: selected ? menuneg : '0px'
});
$('#navbar-height-col').stop().animate({
left: selected ? slideneg : '0px'
});
$(pagewrapper).stop().animate({
left: selected ? '0px' : slidewidth
});
$(navigationwrapper).stop().animate({
left: selected ? '0px' : slidewidth
});
$(this).toggleClass('slide-active', !selected);
$('#slidemenu').toggleClass('slide-active');
$('#page-content, .navbar, body, .navbar-header').toggleClass('slide-active');
});
var selected = '#slidemenu, #page-content, body, .navbar, .navbar-header';
$(window).on("resize", function () {
if ($(window).width() > 767 && $('.navbar-toggle').is(':hidden')) {
$(selected).removeClass('slide-active');
}
});
});
Bootstrap 5 Beta 3 (update 2021)
Introducing the new Bootstrap 5 Offcanvas Component
Bootstrap 4
Create a responsive navbar sidebar "drawer" in Bootstrap 4?
Bootstrap horizontal menu collapse to sidemenu
Bootstrap 3
I think what you're looking for is generally known as an "off-canvas" layout. Here is the standard off-canvas example from the official Bootstrap docs: http://getbootstrap.com/examples/offcanvas/
The "official" example uses a right-side sidebar the toggle off and on separately from the top navbar menu. I also found these off-canvas variations that slide in from the left and may be closer to what you're looking for..
http://www.bootstrapzero.com/bootstrap-template/off-canvas-sidebar
http://www.bootstrapzero.com/bootstrap-template/facebook
Without Plugin, we can do this; bootstrap multi-level responsive menu for mobile phone with slide toggle for mobile:
$('[data-toggle="slide-collapse"]').on('click', function() {
$navMenuCont = $($(this).data('target'));
$navMenuCont.animate({
'width': 'toggle'
}, 350);
$(".menu-overlay").fadeIn(500);
});
$(".menu-overlay").click(function(event) {
$(".navbar-toggle").trigger("click");
$(".menu-overlay").fadeOut(500);
});
// if ($(window).width() >= 767) {
// $('ul.nav li.dropdown').hover(function() {
// $(this).find('>.dropdown-menu').stop(true, true).delay(200).fadeIn(500);
// }, function() {
// $(this).find('>.dropdown-menu').stop(true, true).delay(200).fadeOut(500);
// });
// $('ul.nav li.dropdown-submenu').hover(function() {
// $(this).find('>.dropdown-menu').stop(true, true).delay(200).fadeIn(500);
// }, function() {
// $(this).find('>.dropdown-menu').stop(true, true).delay(200).fadeOut(500);
// });
// $('ul.dropdown-menu [data-toggle=dropdown]').on('click', function(event) {
// event.preventDefault();
// event.stopPropagation();
// $(this).parent().siblings().removeClass('open');
// $(this).parent().toggleClass('open');
// $('b', this).toggleClass("caret caret-up");
// });
// }
// $(window).resize(function() {
// if( $(this).width() >= 767) {
// $('ul.nav li.dropdown').hover(function() {
// $(this).find('>.dropdown-menu').stop(true, true).delay(200).fadeIn(500);
// }, function() {
// $(this).find('>.dropdown-menu').stop(true, true).delay(200).fadeOut(500);
// });
// }
// });
var windowWidth = $(window).width();
if (windowWidth > 767) {
// $('ul.dropdown-menu [data-toggle=dropdown]').on('click', function(event) {
// event.preventDefault();
// event.stopPropagation();
// $(this).parent().siblings().removeClass('open');
// $(this).parent().toggleClass('open');
// $('b', this).toggleClass("caret caret-up");
// });
$('ul.nav li.dropdown').hover(function() {
$(this).find('>.dropdown-menu').stop(true, true).delay(200).fadeIn(500);
}, function() {
$(this).find('>.dropdown-menu').stop(true, true).delay(200).fadeOut(500);
});
$('ul.nav li.dropdown-submenu').hover(function() {
$(this).find('>.dropdown-menu').stop(true, true).delay(200).fadeIn(500);
}, function() {
$(this).find('>.dropdown-menu').stop(true, true).delay(200).fadeOut(500);
});
$('ul.dropdown-menu [data-toggle=dropdown]').on('click', function(event) {
event.preventDefault();
event.stopPropagation();
$(this).parent().siblings().removeClass('open');
$(this).parent().toggleClass('open');
// $('b', this).toggleClass("caret caret-up");
});
}
if (windowWidth < 767) {
$('ul.dropdown-menu [data-toggle=dropdown]').on('click', function(event) {
event.preventDefault();
event.stopPropagation();
$(this).parent().siblings().removeClass('open');
$(this).parent().toggleClass('open');
// $('b', this).toggleClass("caret caret-up");
});
}
// $('.dropdown a').append('Some text');
#media only screen and (max-width: 767px) {
#slide-navbar-collapse {
position: fixed;
top: 0;
left: 15px;
z-index: 999999;
width: 280px;
height: 100%;
background-color: #f9f9f9;
overflow: auto;
bottom: 0;
max-height: inherit;
}
.menu-overlay {
display: none;
background-color: #000;
bottom: 0;
left: 0;
opacity: 0.5;
filter: alpha(opacity=50);
/* IE7 & 8 */
position: fixed;
right: 0;
top: 0;
z-index: 49;
}
.navbar-fixed-top {
position: initial !important;
}
.navbar-nav .open .dropdown-menu {
background-color: #ffffff;
}
ul.nav.navbar-nav li {
border-bottom: 1px solid #eee;
}
.navbar-nav .open .dropdown-menu .dropdown-header,
.navbar-nav .open .dropdown-menu>li>a {
padding: 10px 20px 10px 15px;
}
}
.dropdown-submenu {
position: relative;
}
.dropdown-submenu .dropdown-menu {
top: 0;
left: 100%;
margin-top: -1px;
}
li.dropdown a {
display: block;
position: relative;
}
li.dropdown>a:before {
content: "\f107";
font-family: FontAwesome;
position: absolute;
right: 6px;
top: 5px;
font-size: 15px;
}
li.dropdown-submenu>a:before {
content: "\f107";
font-family: FontAwesome;
position: absolute;
right: 6px;
top: 10px;
font-size: 15px;
}
ul.dropdown-menu li {
border-bottom: 1px solid #eee;
}
.dropdown-menu {
padding: 0px;
margin: 0px;
border: none !important;
}
li.dropdown.open {
border-bottom: 0px !important;
}
li.dropdown-submenu.open {
border-bottom: 0px !important;
}
li.dropdown-submenu>a {
font-weight: bold !important;
}
li.dropdown>a {
font-weight: bold !important;
}
.navbar-default .navbar-nav>li>a {
font-weight: bold !important;
padding: 10px 20px 10px 15px;
}
li.dropdown>a:before {
content: "\f107";
font-family: FontAwesome;
position: absolute;
right: 6px;
top: 9px;
font-size: 15px;
}
#media (min-width: 767px) {
li.dropdown-submenu>a {
padding: 10px 20px 10px 15px;
}
li.dropdown>a:before {
content: "\f107";
font-family: FontAwesome;
position: absolute;
right: 3px;
top: 12px;
font-size: 15px;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<body>
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="slide-collapse" data-target="#slide-navbar-collapse" 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>
<a class="navbar-brand" href="#">Brand</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="slide-navbar-collapse">
<ul class="nav navbar-nav">
<li>Link <span class="sr-only">(current)</span></li>
<li>Link</li>
<li class="dropdown">
Dropdown</span>
<ul class="dropdown-menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li>Separated link</li>
<li>One more separated link</li>
<li class="dropdown-submenu">
SubMenu 1</span>
<ul class="dropdown-menu">
<li>3rd level dropdown</li>
<li>3rd level dropdown</li>
<li>3rd level dropdown</li>
<li>3rd level dropdown</li>
<li>3rd level dropdown</li>
<li class="dropdown-submenu">
SubMenu 2</span>
<ul class="dropdown-menu">
<li>3rd level dropdown</li>
<li>3rd level dropdown</li>
<li>3rd level dropdown</li>
<li>3rd level dropdown</li>
<li>3rd level dropdown</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li>Link</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>Link</li>
<li class="dropdown">
Dropdown</span>
<ul class="dropdown-menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li>Separated link</li>
</ul>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container-fluid -->
</nav>
<div class="menu-overlay"></div>
<div class="col-md-12">
<h1>Resize the window to see the result</h1>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus non bibendum sem, et sodales massa. Proin quis velit vel nisl imperdiet rhoncus vitae id tortor. Praesent blandit tellus in enim sollicitudin rutrum. Integer ullamcorper, augue ut tristique
ultrices, augue magna placerat ex, ac varius mauris ante sed dui. Fusce ullamcorper vulputate magna, a malesuada nunc pellentesque sit amet. Donec posuere placerat erat, sed ornare enim aliquam vitae. Nullam pellentesque auctor augue, vel commodo
dolor porta ac. Sed libero eros, fringilla ac lorem in, blandit scelerisque lorem. Suspendisse iaculis justo velit, sit amet fringilla velit ornare a. Sed consectetur quam eget ipsum luctus bibendum. Ut nisi lectus, viverra vitae ipsum sit amet,
condimentum condimentum neque. In maximus suscipit eros ut eleifend. Donec venenatis mauris nulla, ac bibendum metus bibendum vel.
</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus non bibendum sem, et sodales massa. Proin quis velit vel nisl imperdiet rhoncus vitae id tortor. Praesent blandit tellus in enim sollicitudin rutrum. Integer ullamcorper, augue ut tristique
ultrices, augue magna placerat ex, ac varius mauris ante sed dui. Fusce ullamcorper vulputate magna, a malesuada nunc pellentesque sit amet. Donec posuere placerat erat, sed ornare enim aliquam vitae. Nullam pellentesque auctor augue, vel commodo
dolor porta ac. Sed libero eros, fringilla ac lorem in, blandit scelerisque lorem. Suspendisse iaculis justo velit, sit amet fringilla velit ornare a. Sed consectetur quam eget ipsum luctus bibendum. Ut nisi lectus, viverra vitae ipsum sit amet,
condimentum condimentum neque. In maximus suscipit eros ut eleifend. Donec venenatis mauris nulla, ac bibendum metus bibendum vel.
</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus non bibendum sem, et sodales massa. Proin quis velit vel nisl imperdiet rhoncus vitae id tortor. Praesent blandit tellus in enim sollicitudin rutrum. Integer ullamcorper, augue ut tristique
ultrices, augue magna placerat ex, ac varius mauris ante sed dui. Fusce ullamcorper vulputate magna, a malesuada nunc pellentesque sit amet. Donec posuere placerat erat, sed ornare enim aliquam vitae. Nullam pellentesque auctor augue, vel commodo
dolor porta ac. Sed libero eros, fringilla ac lorem in, blandit scelerisque lorem. Suspendisse iaculis justo velit, sit amet fringilla velit ornare a. Sed consectetur quam eget ipsum luctus bibendum. Ut nisi lectus, viverra vitae ipsum sit amet,
condimentum condimentum neque. In maximus suscipit eros ut eleifend. Donec venenatis mauris nulla, ac bibendum metus bibendum vel.
</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus non bibendum sem, et sodales massa. Proin quis velit vel nisl imperdiet rhoncus vitae id tortor. Praesent blandit tellus in enim sollicitudin rutrum. Integer ullamcorper, augue ut tristique
ultrices, augue magna placerat ex, ac varius mauris ante sed dui. Fusce ullamcorper vulputate magna, a malesuada nunc pellentesque sit amet. Donec posuere placerat erat, sed ornare enim aliquam vitae. Nullam pellentesque auctor augue, vel commodo
dolor porta ac. Sed libero eros, fringilla ac lorem in, blandit scelerisque lorem. Suspendisse iaculis justo velit, sit amet fringilla velit ornare a. Sed consectetur quam eget ipsum luctus bibendum. Ut nisi lectus, viverra vitae ipsum sit amet,
condimentum condimentum neque. In maximus suscipit eros ut eleifend. Donec venenatis mauris nulla, ac bibendum metus bibendum vel.
</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus non bibendum sem, et sodales massa. Proin quis velit vel nisl imperdiet rhoncus vitae id tortor. Praesent blandit tellus in enim sollicitudin rutrum. Integer ullamcorper, augue ut tristique
ultrices, augue magna placerat ex, ac varius mauris ante sed dui. Fusce ullamcorper vulputate magna, a malesuada nunc pellentesque sit amet. Donec posuere placerat erat, sed ornare enim aliquam vitae. Nullam pellentesque auctor augue, vel commodo
dolor porta ac. Sed libero eros, fringilla ac lorem in, blandit scelerisque lorem. Suspendisse iaculis justo velit, sit amet fringilla velit ornare a. Sed consectetur quam eget ipsum luctus bibendum. Ut nisi lectus, viverra vitae ipsum sit amet,
condimentum condimentum neque. In maximus suscipit eros ut eleifend. Donec venenatis mauris nulla, ac bibendum metus bibendum vel.
</p>
</div>
</body>
</html>
Reference JS fiddle
Related
Is it possible to have a fixed menu below a sticky header without a fixed height?
What I am trying to achieve looks like this:
const root = document.getElementById('root');
const button = document.querySelector('button');
const nav = document.querySelector('nav');
let open = false;
function toggleMenu() {
open = !open;
if (open) {
button.innerText = 'Close';
nav.classList.add('open');
root.classList.add('hide-overflow');
} else {
button.innerText = 'Open';
nav.classList.remove('open');
root.classList.remove('hide-overflow');
}
}
button.addEventListener('click', toggleMenu);
#root {
height: 200px;
overflow-y: scroll;
scrollbar-gutter: stable;
}
#root.hide-overflow {
overflow-y: hidden;
}
header {
position: sticky;
top: 0;
background: orange;
}
.banner {
background: cyan;
}
nav {
display: none;
overscroll-behavior: contain;
}
nav.open {
display: block;
position: absolute;
top: 21.5px;
right: 0;
height: calc(100vw - 21.5px);
width: 50%;
background: green;
}
<body>
<div id="root">
<header>
<div class="top">
Header
<button type="button">Open</button>
</div>
<div class="banner">
Banner
</div>
<nav>Menu
<ul>
<li>A</li>
<li>B</li>
<li>C</li>
<li>D</li>
</ul>
</nav>
</header>
<main>
<div>
<p>
</p>
<ul>
<li>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</li>
<li>Duis id sem non risus blandit convallis in ac ipsum.</li>
<li>Mauris iaculis nisi at tellus aliquet vestibulum.</li>
</ul>
<p></p>
<p>
</p>
<ul>
<li>Aenean varius nulla sit amet ex aliquam porttitor.</li>
<li>Fusce ut sapien ut diam elementum elementum.</li>
<li>Maecenas vehicula dui a consectetur tempor.</li>
</ul>
<p></p>
<p>
</p>
<ul>
<li>Morbi nec ante efficitur, malesuada lectus nec, accumsan massa.</li>
<li>Donec vitae arcu sed nunc tristique cursus id et turpis.</li>
<li>Ut mattis ante dictum congue egestas.</li>
<li>Ut a odio gravida, faucibus erat id, fermentum felis.</li>
<li>Suspendisse vitae libero feugiat, iaculis augue et, vestibulum ex.</li>
</ul>
<p></p>
<p>
</p>
<ul>
<li>Proin eleifend velit sit amet gravida tempor.</li>
</ul>
<p></p>
<p>
</p>
<ul>
<li>Nam ut tortor ut leo posuere pharetra quis efficitur nisl.</li>
<li>Suspendisse efficitur elit in lacus mollis, eu facilisis orci vulputate.</li>
<li>Donec vulputate purus ut ligula euismod, eu venenatis tellus commodo.</li>
<li>Praesent semper dui nec mattis lacinia.</li>
<li>Duis dignissim justo quis rhoncus maximus.</li>
</ul>
<p></p>
</div>
</main>
</div>
</body>
This works by offsetting the position/height of the nav by the height of the header .top element.
There are two related answers here which suggest a similar approach:
Fixed left navigation after a certain point with sticky header
How to keep a sticky div below a fixed header
Is there any way to do this if the height of the header is not fixed?
Div should not be over Div with background image with divs inside, but for some reason the about div is displayed over the nav:
body {
margin: 0;
padding: 0;
/*background-color: blue;*/
}
.divider {
background-color: #be2b27;
width: 100%;
height: 100px;
position: absolute;
display: block;
padding: 0;
}
.divider h1 {
font-family: "Nexa Light";
font-size: 2em;
color: white;
text-align:left;
padding-left: 10px;
}
.lorem-text {
font-family: "Menlo";
font-size: 1.2em;
color: white;
}
.start-section {
margin-top: 30px;
/* position: absolute; */
padding-left: 20px;
padding-top: 20px;
}
#start-bg {
background-image: url(water.jpg);
background-color:#9abee1;
background-repeat: round;
height:100%;
position: absolute;
}
#home-head {
font-family: 'Nexa Light';
/* font-size: ; */
padding-top: 30px;
color: white;
}
.nav { }
<div id="start-bg">
<!--<div class="nav"...>...</div>-->
<div class="start-section">
<h1 id="home-head">Landing Page</h1>
<p class="lorem-text">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ornare est in maximus vestibulum.
Mauris eu tincidunt quam.<br> In commodo neque id tortor mattis, non consectetur ante tincidunt.
Nunc ultrices ultricies purus, id finibus justo eleifend sit amet.<br>
Sed in iaculis libero, et gravida nibh.
Proin mollis, nibh eu rhoncus scelerisque, orci ex posuere mi, id pharetra purus est suscipit sapien.
Aliquam fermentum dignissim ultricies. Cras vitae neque tincidunt, tristique neque at, ornare leo.<br>
Integer gravida lectus sed venenatis auctor. Vestibulum sed ligula eget dui ultrices luctus.<br>
Etiam dapibus auctor sollicitudin. Nam vel dui non lorem semper scelerisque. Donec sed condimentum mauris.
Maecenas ac enim sit amet orci sodales porta.
</p>
<img src="http://via.placeholder.com/350x150">
<img src="http://via.placeholder.com/350x150">
<img src="http://via.placeholder.com/350x150"><br>
<img src="http://via.placeholder.com/350x150">
<img src="http://via.placeholder.com/350x150">
<img src="http://via.placeholder.com/350x150"><br>
</div>
</div>
<div class="divider">
<h1>About</h1>
</div>
There must be something wrong with the positions or something or the fact that when the div has a background image it is not registered as holding any content so the about div is displayed above it.
What do I need to do?
I want the div to be displayed after the background image ends and stays there when I remove the images. If you need the nav html and css code i will give it to you.
#start-bg {
background-image: url(water.jpg);
background-color:#9abee1;
background-repeat: round;
height:100%;
position: absolute;
}
If you remove:
position: absolute;
Red bar go to bottom bottom of the page.
A similar question has been asked but it didn't provide a solution for my issue. CSS: On hover show and hide different div's at the same time?
I want to hide a div and display an image in the center of the page at the same time when I hover over my list items.
I tried this but it the second div in the middle of the page still shows on hover.
/* absorbing paddings within the div's width, instead of adding it
on top */
* {
box-sizing: border-box;
}
#container {
width: 100%;
}
header {
padding-top: 10px;
}
h1 {
text-align: center;
font-size: 150%;
}
.a {
width: 7%;
height: 48px;
}
.b {
width: 45%;
height: 48px;
}
.a,
.b {
display: inline-block;
vertical-align: top;
padding: 5px;
padding-top: 10px;
margin: 5px;
margin-right: 195px;
}
.a,
ul {
list-style: none;
line-height: 150%;
padding-top: 15px
}
li a {
text-decoration: none;
color: inherit;
}
.b,
h2 {
text-align: center;
}
.projectImage {
display: none;
}
.a:hover .projectImage {
display: block;
}
.a:hover .b {
display: none;
}
.a,
.image1:hover .projectImage {}
<div id="container">
<header id="title">
<h1>Lorem Ipsum</h1>
</header>
<div class="a">
<ul class="projectList">
<li class="projectImage">Project<span><img class="image1" src="" alt="" height="" /></span></li>
<li>Project<span><img src="" alt="" height="" /></span></li>
<li>Project<span><img src="" alt="" height="" /></span></li>
<li>Project<span><img src="" alt="" height="" /></span></li>
<li>Project<span><img src="" alt="" height="" /></span></li>
<li>Project<span><img src="" alt="" height="" /></span></li>
<li>Project<span><img src="" alt="" height="" /></span></li>
</ul>
</div>
<div class="b">
<h2>lorem ipsum</h2>
<p>Lorem ipsum dolor sit amet, suspendisse nam habitasse pellentesque arcu quae dignissim, amet magna diam aenean. Amet ipsum aenean, massa posuere maecenas nam lectus nibh lacus, nisl lacus magna nullam leo quis. Mi elit ante nunc, mi odio congue rhoncus
dui quis dictum, lectus eleifend aliquam sed venenatis vitae lorem, potenti non dictum sit. Condimentum nonummy vitae tristique, pede nullam pretium arcu vestibulum dictum, urna erat aliquam duis sit pede nam. Morbi mauris fermentum luctus morbi
nec eget, vitae fermentum et maecenas, primis ullamcorper mauris et diam nunc, turpis massa sit felis nullam.</p>
<p>Interdum morbi pellentesque. Et semper diam vestibulum, nisl est, porttitor mauris tellus hac, ut dictum massa. Elementum malesuada curabitur non euismod arcu, sit justo suspendisse aliquam purus suspendisse. Felis est leo, quis turpis ornare quis
tellus, fusce neque ut vitae justo penatibus molestie, per labore suscipit corrupti, non sed in id amet velit. Tempor rutrum tristique anim orci massa, arcu dolor eros dictum arcu.</p>
</div>
</div>
https://codepen.io/jordan_miguel/pen/dWNbzL?editors=1100
Since element .a and element .b are right next to each other in the markup you have supplied, you probably want to use the sibling selector to target element .b. Simply change your last declaration block to:
.a:hover + .b {
display: none;
}
Here's an updated Codepen.
Hope this helps! Let me know if you have any questions.
I'm trying to create a layout - with a left floating div with vertical video/speaker/information divs and a right floating div with chapters - where the containers for chapters and information both cover the rest of the remaining height, with vertical scroll.
An example layout can be found at http://codepen.io/westis/pen/NPLwmy, with the HTML and CSS below. The embedded video is just an example video.
html, body {
font-family: arial, helvetica;
height: 100%;
margin: 0;
}
.title {
font-size: 1.5em;
padding: 0.5em;
margin-top: 0;
margin-bottom: 1em;
border-bottom: 3px solid #000;
text-transform: uppercase;
}
.main-container {
height: 100%;
display: flex;
display: -webkit-flex;
flex-direction: row;
-webkit-flex-direction: row;
}
.left {
width: 59%;
margin-right: 2%;
float: left;
flex-direction: column;
display: flex;
position:relative;
flex-grow: 1;
}
.right {
float: right;
width: 39%;
background: #ff8100;
flex-direction: column;
display: flex;
position:relative;
flex-grow: 1;
}
.video {
position: relative;
padding-bottom: 57.25%;
padding-top: 25px;
height: 0;
z-index: 99;
flex: 1 1 auto;
}
.video iframe, .video video {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.speaker-container {
display: block;
width: 100%;
flex: 1 0 auto;
background: #ccc;
}
.speaker {
display: block;
float: left;
padding: 0.5em;
line-height: 1.5em;
}
.main-container h2 {
font-size: 1.5em;
line-height: 1.5;
font-style: normal;
font-weight: 400;
margin: 0;
}
.info-container {
overflow-y: auto;
flex: 1 0.5 auto;
margin-top: 1em;
}
.info {
background: #739bd2;
padding: 0.5em;
}
.chapter-container {
min-height: 200px;
overflow-y: auto;
}
.chapter-list {
padding: 0;
border-bottom: 1px solid #444;
margin: 0;
list-style: none;
}
.chapter {
display: block;
}
.chapter a {
padding: 0.5em 1em;
border-top: 1px solid #000;
text-decoration: none;
color: #000;
display: block;
}
h2 {
flex: 0 0 auto;
}
footer {
clear: both;
background: #000;
color: #fff;
padding: 1em;
}
<h1 class="title">Agenda title</h1>
<div class="main-container">
<div class="left">
<div class="video"><iframe width="560" height="315" src="https://www.youtube.com/embed/lbtxvWsNERY?rel=0&showinfo=0" frameborder="0" allowfullscreen></iframe></div>
<div class="speaker-container">
<div class="speaker">Some name
</div>
</div>
<div class="info-container">
<div class="info scrollbox">
<h2 class="info-title">Chapter 1</h2>
<div class="info-text"><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas at lobortis sapien. Vivamus lacinia egestas diam et faucibus. Curabitur ac mi fermentum, sodales arcu a, consectetur ipsum. Cras blandit lorem quis erat viverra, at iaculis enim consectetur. Vestibulum vel fermentum erat. Nam at justo ac elit pellentesque semper. Vivamus fringilla mattis nisl ut convallis. Nullam urna sem, pharetra sit amet hendrerit convallis, facilisis sed tortor. Integer suscipit hendrerit sollicitudin. Phasellus tristique orci enim, sit amet varius nulla faucibus quis.</p>
<p>Fusce massa quam, eleifend a ligula ut, porttitor suscipit turpis. Fusce id metus vitae nisi efficitur consequat in vitae arcu. Phasellus euismod hendrerit euismod. Vivamus maximus, nibh in dignissim viverra, massa eros lobortis lorem, at mollis elit purus at felis. Sed iaculis sed lacus a tristique. Mauris porta sodales massa, vel ultricies eros tristique a. Phasellus dolor justo, porta egestas elementum nec, interdum ut orci. Donec id orci nisl. Quisque sed erat nisi. Etiam ultrices nulla sit amet augue ultrices, ut ornare urna mattis.</p>
<p>Sed tortor ante, bibendum nec justo vel, efficitur tincidunt ex. Vestibulum condimentum neque et tincidunt dignissim. Maecenas eu erat ligula. Morbi quis dui a tortor hendrerit euismod. Aenean nibh odio, maximus sed nibh vitae, sagittis egestas sem. Fusce sapien nulla, malesuada molestie eros et, tristique lobortis libero. Quisque eget purus tortor. Sed eros odio, ultrices id ornare non, varius eu tellus. Morbi ante lectus, aliquam fermentum ligula sed, hendrerit luctus turpis. Duis sem neque, tincidunt ut gravida nec, lobortis at eros. Proin ullamcorper dui eu feugiat egestas. Nulla facilisi. Suspendisse a mollis arcu.</p></div>
</div>
</div>
</div>
<div class="right">
<h2>Chapters</h2>
<div class="chapter-container">
<ul class="chapter-list">
<li class="chapter">chapter 1</li>
<li class="chapter">chapter 2</li>
<li class="chapter">chapter 3</li>
<li class="chapter">chapter 4</li>
<li class="chapter">chapter 5</li>
<li class="chapter">chapter 6</li>
<li class="chapter">chapter 7</li>
<li class="chapter">chapter 8</li>
<li class="chapter">chapter 9</li>
<li class="chapter">chapter 10</li>
<li class="chapter">chapter 11</li>
<li class="chapter">chapter 12</li>
<li class="chapter">chapter 13</li>
<li class="chapter">chapter 14</li>
<li class="chapter">chapter 15</li>
<li class="chapter">chapter 16</li>
<li class="chapter">chapter 17</li>
<li class="chapter">chapter 18</li>
<li class="chapter">chapter 19</li>
<li class="chapter">chapter 20</li>
</ul>
</div>
</div>
</div>
<footer>Some footer</footer>
Using flex I have more or less accomplished what I want. But my questions are:
Is it possible to set a min-height to a flex-item, so that the flex
container increases beyond 100% height? As it is now, the info
container below the video and speaker container disappears when
browser is not tall enough.
Also, I seem to need to put flex-shrink to 0 for the
speaker-container div, or else it does not always show. But when
decreasing the browser height, this means that the
speaker-container (flex item) displays on top of the footer. How
can I avoid that?
The issue that CSS flexbox doesn't work properly in IE 10 and below probably
means I cannot accomplish this kind of layout for those
browsers? Some users will use IE9/IE10 so I would either need a fallback or they'd have to accept only having a page scroll.
in my CSS example I've created a horizontal menu with 50px height. Also tried to use a sticky footer but the BODY is longer with the height of the top menu, and because of it a 50px big white place appeared on the bottom of the page under the Footer. [The problem exists on IE10. Not tested in other browsers yet.]
JSFiddle
html file:
<!doctype html>
<html>
<head>
<!-- Load jQuery from Google's CDN -->
<script src="jquery-1.9.1.js"></script>
<!-- Source our javascript file with the jQUERY code -->
<script src="script.js"></script>
<link rel="stylesheet" href="runnable.css" />
</head>
<body>
<div id="header">
<div id="headerline">
<div class="wrapper">
<ul class="navigation">
<li class="logo">
WebApp
</li>
<li class="tmenu">
<span class="menuItem">Site Events</span>
<ul class="smenu">
<li><span>Consulting</span></li>
<li><span>Sales</span></li>
<li><span>Support</span></li>
</ul>
</li>
<li class="tmenu">
<span class="menuItem">Text files</span>
<ul class="smenu">
<li>Company</li>
<li>Mission</li>
<li>Contact Information</li>
</ul>
</li>
</ul>
</div>
</div>
</div>
<div id="content">
<div class="wrapper">
<div class="contentbox">
<h1>Welcome Message</h1>
<p class="date">3/31/2014 - 4:37 PM</p>
<p class="text">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam vel dui tempus, iaculis arcu sit amet, porttitor turpis. Interdum et malesuada fames ac ante ipsum primis in faucibus. Sed eu quam mi. Morbi ac nulla eget diam commodo faucibus. Proin dignissim elit a ligula rhoncus, vitae viverra justo dignissim. In congue quam molestie, mollis ante sed, viverra urna. Pellentesque massa velit, eleifend a magna nec, vulputate gravida dui. Integer pulvinar id arcu ut faucibus. Phasellus vitae augue ac eros sollicitudin vehicula. Nunc aliquam leo a laoreet consequat. Fusce tristique mauris sed neque feugiat, id dignissim dui bibendum. Ut hendrerit commodo mi. Nunc pharetra, eros ut ultricies ultricies, erat lectus vehicula odio, vel suscipit odio nisi eu tellus. Integer interdum adipiscing gravida. Donec vitae neque diam. Mauris interdum eu nulla nec interdum.</p>
<p class="text">Vivamus eu quam ut felis hendrerit mattis ac nec urna. Maecenas erat felis, gravida ut porttitor at, congue eget mauris. Phasellus interdum dolor sem, et gravida massa scelerisque ac. Pellentesque non rhoncus orci. Quisque viverra tellus justo, eu congue mi mattis eget. Fusce a nulla urna. Fusce et mauris eget lorem lacinia sollicitudin. Fusce condimentum neque quis est tristique,aliquet dui sodales.</p>
<p class="text">Donec at velit nec nibh porttitor auctor quis non ipsum. Vestibulum condimentum viverra mattis. Praesent sed quam ultricies magna tempor tristique. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed venenatis nulla eget sapien hendrerit vulputate. Donec sed libero justo. Aliquam diam felis, feugiat ac vulputate vel, iaculis at lorem. Nam facilisis lacus nec turpis bibendum, sit amet rutrum eros ultrices. </p>
<p class="text">Quisque quis scelerisque risus. Fusce a lacinia velit, non vestibulum ipsum. Donec nunc ipsum, semper quis sagittis nec, facilisis id felis. Morbi eget magna volutpat, adipiscing dui ac, elementum est. Curabitur sem diam, rhoncus in lorem eu, sodales eleifend sem. Etiam bibendum convallis fermentum. Donec ullamcorper pulvinar neque in auctor. Vestibulum tincidunt arcu vel orci molestie porta. Quisque quis commodo velit, eget vulputate nibh. Cras eu venenatis tellus. </p>
<p class="text">Duis ultricies accumsan euismod. Nulla pulvinar felis placerat vehicula rutrum. Etiam placerat vitae lacus nec laoreet. In nunc nibh, tincidunt sed dictum sit amet, ultrices vel enim. Nulla in urna molestie, pulvinar massa non, consectetur augue. Ut et ligula vitae libero vehicula mollis. Suspendisse nisl felis, pretium eget libero in, pharetra porttitor lectus. Nunc tincidunt nunc neque. Donec eget interdum ante. Pellentesque vehicula sapien eu lectus tempus interdum. Suspendisse pharetra purus id lectus cursus dapibus. Proin sed lorem dignissim, placerat est sit amet, blandit diam. Ut ut risus vitae neque sodales rhoncus nec ac massa. Fusce ac augue tincidunt, vulputate augue sit amet, varius tellus. Vivamus a tortor ipsum. Vestibulum in tellus neque.</p>
</div>
</div>
</div>
<div id="footer">
<div id="fback">
<div class="wrapper">
<div id="fContent">
<ul><p>Help</p>
<li>About WebApp</li>
<li>List Item</li>
<li>List Item</li>
<li>List Item</li>
<li>List Item</li>
<li>List Item</li>
<li>List Item</li>
<li>List Item</li>
</ul>
<ul><p>FAQ</p>
<li>Question</li>
<li>Question</li>
<li>Question</li>
</ul>
<ul><p>Contacts</p>
<li>Person</li>
<li>Person</li>
<li>Person</li>
<li>Person</li>
<li>Person</li>
<li>Person</li>
</ul>
</div>
</div>
</div>
</div>
</body>
</html>
CSS file:
* {
margin: 0;
padding: 0;
}
html {
height: 100%;
/*border: 2px solid red;*/
}
body {
font-family: arial;
text-align: center;
background:url(foo) fixed;
height: 100%;
/*border: 2px solid red;*/
}
div.wrapper {
width: 1100px;
margin: 0 auto;
padding: 0;
}
/*=== header ===*/
div#header {
text-align: center;
position: fixed;
_position: absolute;
top: 0;
left: 0;
_top:expression(eval(document.body.scrollTop));
display: block;
width: 100%;
}
div#headerline {
padding: 0;
margin: 0;
background: #e6e6e6;
height: 50px;
border-bottom: solid 1px #172740;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
}
ul.navigation li{
float: left;
}
ul.navigation a {
text-decoration: none;
display: block;
}
span.menuItem {
display: inline;
display: inline-table;
display: inline-block;
line-height: 68px;
}
li.logo {
font-family: tahoma;
font-size: 40px;
font-weight: bold;
}
li.logo a {
padding: 0;
height: 50px;
width: 180px;
text-align: left;
}
li.tmenu {
float: left;
width: 160px;
position: relative;
}
li.logo a, li.tmenu > a { /* ">" means the first level of this type of children*/
color: #172740;
text-shadow: 2px 2px white;
}
li.tmenu a {
width: 160px;
height: 50px;
}
li.tmenu > a {
font-weight: 600;
}
li.tmenu > a:hover {
font-weight: 900;
}
ul.smenu {
display: none;
position: absolute;
margin-left: 0px;
list-style: none;
padding: 0px;
background: #172740;
border: solid 1px #000;
}
ul.smenu, ul.smenu li {
width: 160px;
float: left;
}
ul.smenu a {
display: block;
height: 20px;
padding: 8px 0px;
color: #fff;
text-decoration: none;
text-align: center;
text-shadow: 1px 1px #000;
}
ul.smenu a:hover {
font-weight: bold;
}
/*=== content ===*/
div#content {
text-align: left;
/*position: relative;*/
min-height: 60%;
margin-top: 50px;
}
h1 {
padding: 0;
margin: 0;
padding-top: 50px;
color: #253e66;
font-size: 25px;
}
p.date {
font-size: 8px;
color: #aaa;
}
p.text {
font-size: 14px;
margin-bottom: 6px;
}
/*=== Footer ===*/
div#footer {
padding-top: 50px;
width: 100%;
min-height: 20%;
}
div#fback {
overflow: hidden;
padding: 0;
margin: 0;
background: #253e66;
text-align: center;
}
div#fContent {
color: #e6e6e6;
text-align: center;
}
div#fContent ul {
text-align: left;
float: left;
padding: 40px 70px 50px 0px;
font-size: 14px;
}
div#fContent ul > p {
font-weight: bold;
padding-bottom: 12px;
}
div#fContent li {
padding-bottom: 3px;
}
/*=== Copyright content ===*/
JS file:
$(document).ready(
/* This is the function that will get executed after the DOM is fully loaded */
function () {
/* Next part of code handles hovering effect and submenu appearing */
$('.tmenu').hover(
function () { //appearing on hover
$('ul', this).fadeIn();
},
function () { //disappearing on hover
$('ul', this).fadeOut();
}
);
}
);
Also weird that, if I set a border on the BODY, big part of the white space is disappear. Please help me out, what I've messed in the CSS, and how can I repair my code. Thanks a lot in advance.
sorry the was indeed a problem didnt understand the question.
I changed div#fContent ul from:
div#fContent ul {
text-align: left;
float: left;
padding: 40px 70px 50px 0px;
font-size: 14px;
}
to:
div#fContent ul {
text-align: left;
float: left;
padding: 40px 70px 0px 0px;
font-size: 14px;
}
Good luck. Check the fiddle and let me know:
DEMO
don't quote me on this please... but I think that the the paragraph element gives white space so to remove this make its margin 0px. Hope it's the right answer if not please comment back MontyX. thanks