css navigation bar position fixed not working - html

I am trying to make a website. I decided to make the navigation bar have a fixed position so when I scroll down I can always see it but, when I add to the nav element the property position:fixed it just disappears. Cant' figure out what's happening. Can someone explain, what I'm doing wrong? Thank you very much!
P.S: I am new to coding.
HTML and CSS
* {
box-sizing: border-box;
padding: 0;
margin: 0;
}
html,
body {
width: 100%;
height: 100%;
}
header nav #logo {
width: 140px;
position: absolute;
top: 15px;
}
nav {
position: relative;
background-color: #242628;
height: 70px;
padding-left: 20px;
}
nav ul {
position: absolute;
height: 100%;
margin: auto;
top: 0;
bottom: 0;
width: 600px;
padding-left: 200px;
}
nav ul li {
-moz-transition: all 0.2s linear;
-webkit-transition: all 0.2s linear;
-o-transition: all 0.2s linear;
transition: all 0.2s linear;
display: inline;
float: left;
height: inherit;
width: 100px;
border-right: 1px solid gray;
}
nav ul li:hover {
background-color: rgba(12, 240, 255, 0.3);
}
nav ul li a {
color: white;
text-decoration: none;
position: absolute;
height: inherit;
width: inherit;
text-align: center;
padding-top: 25px;
}
<header>
<nav>
<img id="logo" src="images/logo.png" alt="logo" />
<ul>
<li>Home</li>
<li>Rate it!</li>
<li>Courses</li>
<li>Videos</li>
</ul>
</nav>
</header>

Once you fix the position you have to specify where you want it.
top: 20px;
left: 0px;
Etc....

You have to add a width to fixed elements (100% in this case):
* {
box-sizing: border-box;
padding: 0;
margin: 0;
}
html,
body {
width: 100%;
height: 100%;
}
header nav #logo {
width: 140px;
position: absolute;
top: 15px;
}
nav {
position: fixed;
width: 100%;
background-color: #242628;
height: 70px;
padding-left: 20px;
}
nav ul {
position: absolute;
height: 100%;
margin: auto;
top: 0;
bottom: 0;
width: 600px;
padding-left: 200px;
}
nav ul li {
-moz-transition: all 0.2s linear;
-webkit-transition: all 0.2s linear;
-o-transition: all 0.2s linear;
transition: all 0.2s linear;
display: inline;
float: left;
height: inherit;
width: 100px;
border-right: 1px solid gray;
}
nav ul li:hover {
background-color: rgba(12, 240, 255, 0.3);
}
nav ul li a {
color: white;
text-decoration: none;
position: absolute;
height: inherit;
width: inherit;
text-align: center;
padding-top: 25px;
}
<header>
<nav>
<img id="logo" src="images/logo.png" alt="logo" />
<ul>
<li>Home</li>
<li>Rate it!</li>
<li>Courses</li>
<li>Videos</li>
</ul>
</nav>
</header>

I let you here a working version. I only replaced relative with fixed in your code to the nav
* {
box-sizing: border-box;
padding: 0;
margin: 0;
}
html,
body {
width: 100%;
height: 300%;
}
header nav #logo {
width: 140px;
position: absolute;
top: 15px;
}
nav {
position: fixed;
background-color: #242628;
height: 70px;
padding-left: 20px;
}
nav ul {
position: absolute;
height: 100%;
margin: auto;
top: 0;
bottom: 0;
width: 600px;
padding-left: 200px;
}
nav ul li {
-moz-transition: all 0.2s linear;
-webkit-transition: all 0.2s linear;
-o-transition: all 0.2s linear;
transition: all 0.2s linear;
display: inline;
float: left;
height: inherit;
width: 100px;
border-right: 1px solid gray;
}
nav ul li:hover {
background-color: rgba(12, 240, 255, 0.3);
}
nav ul li a {
color: white;
text-decoration: none;
position: absolute;
height: inherit;
width: inherit;
text-align: center;
padding-top: 25px;
}
<header>
<nav>
<img id="logo" src="images/logo.png" alt="logo" />
<ul>
<li>Home</li>
<li>Rate it!</li>
<li>Courses</li>
<li>Videos</li>
</ul>
</nav>
</header>
Note that I set height to 300% to have some scroll on the document

I honestly don't see anything wrong:
http://codepen.io/anon/pen/BWpLdd
.scrollTest {
height: 2000px;
background: -moz-linear-gradient(top, #a90329 0%, #8f0222 44%, #6d0019 100%); /* FF3.6-15 */
background: -webkit-linear-gradient(top, #a90329 0%,#8f0222 44%,#6d0019 100%); /* Chrome10-25,Safari5.1-6 */
background: linear-gradient(to bottom, #a90329 0%,#8f0222 44%,#6d0019 100%);
}
* {
box-sizing: border-box;
padding: 0;
margin: 0; }
html, body {
width: 100%;
height: 100%; }
header nav #logo {
width: 140px;
position: absolute;
top: 15px; }
nav {
position: fixed;
background-color: #242628;
height: 70px;
padding-left: 20px;
width: 100%;
}
nav ul {
position: absolute;
height: 100%;
margin: auto;
top: 0;
bottom: 0;
width: 800px;
padding-left: 200px; }
nav ul li {
-moz-transition: all 0.2s linear;
-webkit-transition: all 0.2s linear;
-o-transition: all 0.2s linear;
transition: all 0.2s linear;
display: inline-block;
height: inherit;
width: 100px;
border-right: 1px solid gray; }
nav ul li:hover {
background-color: rgba(12, 240, 255, 0.3); }
nav ul li a {
color: white;
text-decoration: none;
position: absolute;
height: inherit;
width: inherit;
text-align: center;
padding-top: 25px; }
Make sure you're adding it to the nav parent element.

* {
box-sizing: border-box;
padding: 0;
margin: 0;
}
html,
body {
width: 100%;
height: 100%;
}
header nav #logo {
width: 140px;
position: absolute;
top: 15px;
}
nav {
position: fixed;
background-color: #242628;
height: 70px;
padding-left: 20px;
width: 100%;
background-color: black;
}
nav ul {
position: relative;
height: 100%;
margin: auto;
top: 0;
bottom: 0;
}
nav ul li {
-moz-transition: all 0.2s linear;
-webkit-transition: all 0.2s linear;
-o-transition: all 0.2s linear;
transition: all 0.2s linear;
display: inline;
float: left;
height: inherit;
width: 200px;
border-right: 1px solid gray;
}
nav ul li:hover {
background-color: rgba(12, 240, 255, 0.3);
}
nav ul li a {
color: white;
text-decoration: none;
position: absolute;
height: inherit;
width: inherit;
text-align: center;
padding-top: 25px;
}
article{
height: 500px;
}
<header>
<nav>
<img id="logo" src="" alt="logo" />
<ul>
<li>Home</li>
<li>Rate it!</li>
<li>Courses</li>
<li>Videos</li>
</ul>
</nav>
</header>
<article></article>
Working code

If your nav is set to realtive and is changed to fixed your absolute elements will be relative to the body and those elements will leave the nav.
Change the position of the absolute elements and the css of the nav to:
nav {
background-color: #242628;
height: 70px;
padding-left: 20px; }
position: fixed;
top: 0;
left: 0;
width: 100%;
z-index: 999;
}

Related

How to make two submenu in sidebar

I want to create 2 submenus when the menu in the sidebar is clicked
Here what i've done
$(document).ready(function () {
$("[data-toggle]").click(function () {
var toggle_el = $(this).data("toggle");
$(toggle_el).toggleClass("open-sidebar");
});
$('.parent').click(function () {
$('.submenu').toggle('visible');
});
});
body, html {
height: 100%;
margin: 0;
overflow:hidden;
font-family: helvetica;
font-weight: 100;
}
.container {
position: relative;
height: 100%;
width: 100%;
right: 0;
-webkit-transition: right 0.4s ease-in-out;
-moz-transition: right 0.4s ease-in-out;
-ms-transition: right 0.4s ease-in-out;
-o-transition: right 0.4s ease-in-out;
transition: right 0.4s ease-in-out;
}
.container.open-sidebar {
right: 240px;
}
#sidebar {
position: absolute;
right: -240px;
background: #DF314D;
width: 240px;
height: 100%;
box-sizing: border-box;
-moz-box-sizing: border-box;
border-radius: 4px;
}
#sidebar ul {
margin: 0;
padding: 0;
list-style: none;
}
#sidebar ul li {
margin: 0;
}
#sidebar ul li a {
padding: 15px 20px 15px 35px;
font-size: 16px;
font-weight: 100;
color: white;
text-decoration: none;
display: block;
border-bottom: 1px solid #C9223D;
-webkit-transition: background 0.3s ease-in-out;
-moz-transition: background 0.3s ease-in-out;
-ms-transition: background 0.3s ease-in-out;
-o-transition: background 0.3s ease-in-out;
transition: background 0.3s ease-in-out;
}
#sidebar li:hover {
background: #C9223D;
border-radius: 4px;
}
.main-content {
width: 100%;
height: 100%;
padding: 10px;
box-sizing: border-box;
-moz-box-sizing: border-box;
position: relative;
}
.main-content .content{
box-sizing: border-box;
-moz-box-sizing: border-box;
padding-left: 60px;
width: 100%;
}
.main-content .content h1{
font-weight: 100;
}
.main-content .content p{
width: 100%;
line-height: 160%;
}
.main-content #sidebar-toggle {
background: #DF314D;
border-radius: 3px;
display: block;
position: relative;
padding: 10px 7px;
float: right;
}
.main-content #sidebar-toggle .bar{
display: block;
width: 18px;
margin-bottom: 3px;
height: 2px;
background-color: #fff;
border-radius: 1px;
}
.main-content #sidebar-toggle .bar:last-child{
margin-bottom: 0;
}
.main-content #sidebar-toggle .bar{
display: block;
width: 18px;
margin-bottom: 3px;
height: 2px;
background-color: #fff;
border-radius: 1px;
}
.main-content #sidebar-toggle .bar:last-child{
margin-bottom: 0;
}
.menu a.home {
display: inline-block;
background: url(../imagenes/bpi.png) no-repeat 4px 10px;
}
.menu a.explore {
display: inline-block;
background: url(../imagenes/gasi.png) no-repeat 4px 10px;
}
.menu a.users {
display: inline-block;
background: url(../imagenes/bicici.png) no-repeat 4px 10px;
}
.menu a.signout {
display: inline-block;
background: url(../imagenes/bai.png) no-repeat 4px 10px;
}
#sidebar .menu .submenu {
display: none;
}
#sidebar ul li ul.visible{
display: block;
}
.submenu a.home {
display: inline-block;
background: url(../imagenes/bpi.png) no-repeat 4px 10px;
}
.submenu a.users {
display: inline-block;
background: url(../imagenes/bicici.png) no-repeat 4px 10px;
}
.submenu a.signout {
display: inline-block;
background: url(../imagenes/bai.png) no-repeat 4px 10px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<div class="container">
<div id="sidebar">
<ul class="menu">
<li class="parent">Home ></li>
<ul class="submenu">
<li>Home 11</li>
<li>Home 12</li>
<li>Home 13</li>
</ul>
<li>Explore</li>
<li> Users</li>
<li class="parent"> Sign Out ></li>
<ul class="submenu">
<li>Home 11</li>
<li>Home 12</li>
<li>Home 13</li>
</ul>
</ul>
</div>
<div class="main-content">
<a href="#" data-toggle=".container" id="sidebar-toggle">
<span class="bar"></span>
<span class="bar"></span>
<span class="bar"></span>
</a>
<div class="content">
</div>
</div>
</div>

Drop Down Menu does not stay centered when browser resize

The problem I am having is the formatting of the CSS once the windows resize to smaller. I have been having a lot of trouble, and think that the problem lies in my initial code; I just am not sure where.
I am pretty new to coding and hoping to learn.
.nav-main {
position: absolute;
top: 0;
height: 65px;
width: 100%;
text-align: center;
}
.nav-main ul {
position: relative;
margin: 0 auto;
padding: 0;
list-style: none;
font-size: 22px;
line-height: 100%;
font-family: 'Futura W01 Bold', sans-serif;
text-align: center;
text-transform: uppercase;
display: inline-block;
width: 100%;
}
.nav-top {
position: relative;
margin: 0;
padding: 0 66px 0 50px;
float: none;
display: inline-block;
list-style: none;
}
.nav-top:first-child {
padding-left: 0;
}
.nav-top:last-child {
background-image: none;
padding-right: 0;
}
.nav-top:last-child:after {
content: none;
}
.nav-top > a {
position: relative;
display: block;
margin: 0;
color: #6f6f6f;
text-decoration: none;
padding-top: 20px;
padding-bottom: 5px;
-moz-transition: all 0.3s ease;
-ms-transition: all 0.3s ease;
-o-transition: all 0.3s ease;
transition: all 0.3s ease;
}
.nav-top a:hover,
.nav-top.active > a {
color: #454545;
border-bottom: 4px solid #00e9d9;
text-decoration: none;
}
.nav-top ul {
display: block;
position: absolute;
left: -8.75px;
width: 105%;
top: calc(100% - 1px);
border-bottom-left-radius: .3em;
border-bottom-right-radius: .3em;
}
.nav-top:hover ul {
position: absolute;
top: calc(100% - 1px);
left: -8.75px;
width: 105%;
}
.nav-top li {
float: center;
background-color: #e9e9e9;
padding-top: 16px;
padding-bottom: 10px;
text-align: inherit;
}
.nav-top li:last-child {
padding-bottom: 16px;
border-bottom-left-radius: .3em;
border-bottom-right-radius: .3em;
}
.nav-top li > a {
position: relative;
display: inline;
margin: 0;
color: #6f6f6f;
text-decoration: none;
padding-top: 20px;
-moz-transition: all 0.3s ease;
-ms-transition: all 0.3s ease;
-o-transition: all 0.3s ease;
transition: all 0.3s ease;
}
.nav-top:after {
display: block;
position: absolute;
left: 100%;
top: -17px;
width: 22px;
z-index: 1;
transform: translateX(-50%);
height: 100%;
-ms-transform: translateX(-50%);
-webkit-transform: translateX(-50%);
}
#media only screen and (max-width:960px) {
.nav-main ul {
font-size: 18px;
}
.nav-top ul {
font-size: 15px;
}
.nav-main li {
padding: 0 46px 0 30px; /* 0 66 0 50 */
}
.nav-top li {
padding-top: 11px;
text-align: center;/* top 16 bottom 10*/
float: center;
}
<nav class="nav-main" role="navigation">
<ul>
<li class="nav-top">Welcome</li>
<li class="nav-top">About
<ul class="drop-down">
<li class="nav-drop">Services</li>
<li class="nav-drop">Clients</li>
<li class="nav-drop">Press</li>
<li class="nav-drop">Leadership</li>
<li class="nav-drop">Follow Us</li>
</ul>
</li>
<li class="nav-top">Contact</li>
</ul>
<span class="nav-arrow"></span>
</nav>
JSFIDDLEJS fiddle
Your .nav-main li on #media only screen and (max-width:960px) is affecting it.
You could either use the :not selector .nav-main li:not(.nav-drop) or overwrite the .nav-drop with padding-left: 0; padding-right: 0.
Don't forget to revise it in case you use other media queries.
JSFiddle

How to inherit photo when hover on links under navigation bar?

I made a navigiation bar that changes photo on hover. It works when I hover on links (first level menu) but when I hover on the dropdown's (second level menu) the photo goes off. How do I make photo to stay when hover on both main menu and submenu (dropdown). The photo should not disappear when I hover on submenu.
I would like to achieve this without using JavaScript, purely with CSS.
nav{
background-color: #fff;
width:150px;
height: 667px;
float:right;
}
nav h1{
padding: 20px;
color: #777;
font: 20px tahoma,times,serif;
}
ul {
position: relative;
margin: 0;
padding: 0;
list-style: none;
width: 150px;
text-align: right;
}
ul li {
position: relative;
}
li ul {
position: absolute;
right: 149px;
top: 0;
display: none;
}
ul li a {
display: block;
text-decoration: none;
color: #777;
background: #fff;
padding: 5px;
border-bottom: 0;
}
ul {
margin: 0;
padding: 0;
list-style: none;
width: 150px;
}
li:hover ul {
display: block;
}
* {
margin: 0;
padding: 0;
}
body {
background: #333;
background: url("http://vignette1.wikia.nocookie.net/logopedia/images/6/69/FC-Barcelona-old-logo.png/revision/latest?cb=20120211172615");
background-repeat: no-repeat;
}
.container{
overflow: hidden;
margin-right: 0;
height: 500px;
-webkit-box-shadow: 10px 10px 10px rgba(0,0,0,0.3);
box-shadow: 10px 10px 10px rgba(0,0,0,0.3);
width: 800px;
}
.container img{
margin-top: 0px auto;
position: fixed;
top: 0px;
left: 0px;
z-index: -60;
height: 500px;
width: 800px;
}
.container li img {
opacity: 0.5;
margin-top: 0px auto;
position: absolute;
left: 0px;
z-index: -50;
-webkit-transition: all 1s ease;
-moz-transition: all 1s ease;
-o-transition: all 1s ease;
-ms-transition: all 1s ease;
transition: all 1s ease;
}
li:nth-child(1){
padding-top: 0px;
}
li a:hover {
background: #eee;
}
li a:hover + img {
opacity: 1;
position: fixed;
margin-top: 0px auto;
left: 0px auto;
height: 500px;
width: 800px;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<LINK rel=stylesheet type="text/css" href="StyleSheet.css"/>
<title></title>
</head>
<body>
<div class="container">
<nav><h1><b>ברצלונה</b></h1>
<ul>
<li>ברצלונה<img src="http://media3.fcbarcelona.com/media/asset_publics/resources/000/160/456/size_640x360/pic_2015-01-11_BARCELONA-ATLETICO_45.v1431011244.JPG" alt="1"></li>
<li>לה ליגה<img src="https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcTd6ngNNGapdLhqdS4KbuoNNCaaUMP4Svu-e_9rXMh_wLDtPpSE" alt="1">
<ul>
<li>ברצלונה</li>
<li>ריאל</li>
<li>אתלטיקו</li>
</ul>
</li>
<li>בונדסליגה<img src="http://static3.demotix.com/sites/default/files/imagecache/a_scale_large/2000-5/photos/1368393557-club-atletico-de-madrid-v-fc-barcelona--la-liga_2046465.jpg" alt="1">
<ul>
<li>באיירן</li>
<li>וולפסבורג</li>
<li>הנדובר</li>
<li>דורטמונד</li>
</ul>
</li>
<li>סיירה א<img src="http://barcelonacamps.com/wp-content/uploads/2014/04/barca-new-team.jpg" alt="1">
<ul>
<li>אינטר</li>
<li>מילאן</li>
<li>יובה</li>
<li>רומא</li>
</ul>
</ul>
</li>
</nav>
</div>
</body>
</html>
See this fiddle
Just do the below slight change in your CSS..
Replace
li a:hover + img {
opacity: 1;
position: fixed;
margin-top: 0px auto;
left: 0px auto;
height: 500px;
width: 800px;
}
with
li:hover a +img {
opacity: 1;
position: fixed;
margin-top: 0px auto;
left: 0px auto;
height: 500px;
width: 800px;
}
Also, your <li> and <ul> tags are not properly closed at the end. Bring </li> before the </ul>.

Slide sidebar into view on mouse click

I'm trying to create my own toggleable sidebar. I've done this snippet (press the brown color in screen to toggle):
I'd like that the background had the full width of the screen so when i hit on the brown part, the background is brown,not white.
$(document).ready(function() {
$("#rest-of-the-page").click(
function() {
$("#sidebar").toggleClass("hidden");
}
);
});
html,
body {
height: 100%;
margin: 0;
}
.container {
background-size: cover;
background-repeat: no-repeat;
background-position: center;
height: 100%;
}
#sidebar {
position: absolute;
height: 100%;
width: 15%;
background-color: rgba(27, 26, 26, .8);
transition: all .2s linear 0s;
}
.hidden {
margin-left: -30%;
transition: all .2s linear 0s;
}
#logo-container {
min-height: 150px;
height: 30%;
width: 100%;
border-bottom: 3px solid #1A1A1A;
}
#logo {
width: 100%;
height: 100%;
background: url(Images/logo.png) no-repeat center center;
background-size: 75% auto;
}
.menu-options-container {
height: 50%;
width: 100%;
}
#menu-options-ul {
width: 100%;
list-style-type: none;
padding: 0;
margin: 0;
text-align: center;
height: 70%;
}
#menu-options-ul li {
width: 100%;
border-top: 2px solid #373737;
border-bottom: 2px solid #1A1A1A;
height: 3em;
margin-top: 0;
color: #999;
display: table;
}
#menu-options-ul li:hover {
background: rgba(255, 255, 255, 0.2);
}
#menu-options-ul li p {
vertical-align: middle;
display: table-cell;
width: 100%;
}
#menu-options-ul li p:hover {
color: #fff;
}
#rest-of-the-page {
position: absolute;
top: 0;
left: 15%;
width: 85%;
height: 100%;
transition: all .2s linear 0s;
cursor: pointer;
background-color: antiquewhite
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="container">
<div id="sidebar">
<div id="logo-container">
<div id="logo"></div>
</div>
<div class="menu-options-container">
<ul id="menu-options-ul">
<li>
<p>Hola</p>
</li>
<li>
<p>Adios</p>
</li>
<li>
<p>Buenas</p>
</li>
</ul>
</div>
</div>
<div id="rest-of-the-page"></div>
</div>
just add a class with left:0 name it "fullpage"
make the width 100% for #rest-of-the-page
#rest-of-the-page{
position:absolute;
top:0;
width:100%;
left:15%;
height:100%;
transition: all .2s linear 0s;
cursor:pointer;
background-color:antiquewhite
}
#rest-of-the-page.fullpage{
left:0;
}
UPDATE : Another thing make the margin-left : -15% and not -30% because the width of the sidebar is only 15%
.hidden{
margin-left: -15%;
transition: all .2s linear 0s; //you don't need this
}
add overflow hidden to body
html, body {
height: 100%;
margin:0;
overflow-x:hidden;
}
toggleClass fullpage for #rest-of-the-page
https://jsfiddle.net/yggt4s83/2/
You can add the background color of the #rest-of-the-page element to your body:
$(document).ready(function() {
$("#rest-of-the-page").click(
function() {
$("#sidebar").toggleClass("hidden");
}
);
});
html,
body {
height: 100%;
margin: 0;
background-color: antiquewhite
}
.container {
background-size: cover;
background-repeat: no-repeat;
background-position: center;
height: 100%;
}
#sidebar {
position: absolute;
height: 100%;
width: 15%;
background-color: rgba(27, 26, 26, .8);
transition: all .2s linear 0s;
}
.hidden {
margin-left: -30%;
transition: all .2s linear 0s;
}
#logo-container {
min-height: 150px;
height: 30%;
width: 100%;
border-bottom: 3px solid #1A1A1A;
}
#logo {
width: 100%;
height: 100%;
background: url(Images/logo.png) no-repeat center center;
background-size: 75% auto;
}
.menu-options-container {
height: 50%;
width: 100%;
}
#menu-options-ul {
width: 100%;
list-style-type: none;
padding: 0;
margin: 0;
text-align: center;
height: 70%;
}
#menu-options-ul li {
width: 100%;
border-top: 2px solid #373737;
border-bottom: 2px solid #1A1A1A;
height: 3em;
margin-top: 0;
color: #999;
display: table;
}
#menu-options-ul li:hover {
background: rgba(255, 255, 255, 0.2);
}
#menu-options-ul li p {
vertical-align: middle;
display: table-cell;
width: 100%;
}
#menu-options-ul li p:hover {
color: #fff;
}
#rest-of-the-page {
position: absolute;
top: 0;
left: 15%;
width: 85%;
height: 100%;
transition: all .2s linear 0s;
cursor: pointer;
background-color: antiquewhite
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="container">
<div id="sidebar">
<div id="logo-container">
<div id="logo"></div>
</div>
<div class="menu-options-container">
<ul id="menu-options-ul">
<li>
<p>Hola</p>
</li>
<li>
<p>Adios</p>
</li>
<li>
<p>Buenas</p>
</li>
</ul>
</div>
</div>
<div id="rest-of-the-page"></div>
</div>
Why don't you add or remove a class on your #Rest-of-page when you toggle your menu ? Like that, your content will always stick to right side of the page if you have some. No tricky things using absolute position etc involved.
Just like this, ( exemple here )
HTML :
<div class="container">
<div id="sidebar">
<div id="logo-container">
<div id= "logo"></div>
</div>
<div class="menu-options-container">
<ul id="menu-options-ul">
<li><p>Hola</p></li>
<li><p>Adios</p></li>
<li><p>Buenas</p></li>
</ul>
</div>
</div>
<div id="rest-of-the-page" class="page--sided"><p>Hello</p></div>
</div>
CSS :
html, body {
height: 100%;
margin:0;
}
.container{
background-size: cover;
background-repeat: no-repeat;
background-position: center;
height: 100%;
}
#sidebar {
position:absolute;
height: 100%;
width: 15%;
background-color: rgba(27, 26, 26, .8);
transition: all .2s linear 0s;
}
.hidden{
margin-left: -30%;
transition: all .2s linear 0s;
}
#logo-container {
min-height: 150px;
height: 30%;
width: 100%;
border-bottom: 3px solid #1A1A1A;
}
#logo {
width: 100%;
height: 100%;
background:url(Images/logo.png) no-repeat center center;
background-size: 75% auto;
}
.menu-options-container {
height: 50%;
width: 100%;
}
#menu-options-ul{
width: 100%;
list-style-type: none;
padding:0;
margin:0;
text-align: center;
height:70%;
}
#menu-options-ul li{
width: 100%;
border-top: 2px solid #373737;
border-bottom: 2px solid #1A1A1A;
height:3em;
margin-top:0;
color: #999;
display: table;
}
#menu-options-ul li:hover{
background: rgba(255,255,255,0.2);
}
#menu-options-ul li p{
vertical-align: middle;
display: table-cell;
width: 100%;
}
#menu-options-ul li p:hover{
color: #fff;
}
#rest-of-the-page{
height:100%;
transition: all .2s linear 0s;
cursor:pointer;
background-color:antiquewhite
}
.page--sided{
position:absolute;
top:0;
left:15%;
width: 85%;
}
.page--full{
width:100%;
}
JS :
$(document).ready(function () {
$("#rest-of-the-page").click(
function () {
$("#sidebar").toggleClass("hidden");
if ($("#rest-of-the-page").hasClass("page--sided")){
$("#rest-of-the-page").removeClass("page--sided")
$("#rest-of-the-page").addClass("page--full");
}else{
$("#rest-of-the-page").addClass("page--sided")
$("#rest-of-the-page").removeClass("page--full");
}
}
);
});
var a = true;
function show(sidebar){
if(a==true){
sidebar.style.left = "0px";
sidebar.style.transition = "left 0.6s linear";
a=false;
}
else{
sidebar.style.left = "-200px";
sidebar.style.transition = "left 0.6s linear";
a=true;
}
}
body{
margin: 0px;
padding:0px;
font-family: helvetica;
}
#sidebar{
width: 200px;
height: 100%;
background: #151718;
top:0px;
left:-200px;
position: absolute;
}
#sidebar ul{
margin-top: 10px;
padding: 0px;
}
#sidebar ul li{
list-style: none;
}
#sidebar ul li a{
color:white;
padding:10px;
width: 180px;
margin-bottom: 4px;
display: block;
border-bottom: 1px solid black;
text-decoration:none;
}
#btn{
margin: 20px;
padding:20px;
right: -90px;
position: absolute;
}
#btn span{
background: black;
width: 25px;
height:5px;
margin-bottom: 5px;
display: block;
border-radius:17px;
}
<div id="sidebar">
<div id="btn" onclick="show(sidebar)">
<span></span>
<span></span>
<span></span>
</div>
<ul>
<li>Facebook</li>
<li>Vk</li>
<li>google</li>
<li>ymail</li>
</ul>
</div>
**Html left Sidebar using CSS and Javascript **

Fixed Div Overflow is Off Screen

I have a sidebar that is fixed with a height of 100%. This sidebar is below a fixed header so the top is below the header.
This causes the overflow scrolling to not reach the last element or two:
JSFiddle
Here is the HTML:
<div class="header">
<div class="header-inner">
<h1 class="header-image"><img src="/" id="logo" alt="Header Test"/></h1>
<nav class="menu">
<ul class="nav-lvl-1">
<li>Home</li>
<li>Link1 </li>
<li><a class="has-sub-menu" href="http://google.com/nav">Link2</a>
<ul id="test" class="nav-lvl-2">
<li>Sublink1</li>
<li>Sublink2</li>
<li>Sublink3</li>
<li>Sublink4</li>
<li>Sublink5</li>
<li>Sublink6</li>
<li>Sublink7</li>
<li>Sublink8</li>
<li>Sublink9</li>
<li>Sublink10</li>
<li>Sublink11</li>
<li>Sublink12</li>
</ul>
</li>
<li>Link3</li>
<li><a class="has-sub-menu" href="http://google.com/nav">Link4</a>
<ul class="nav-lvl-2">
<li>Sublink1</li>
<li>Sublink2</li>
<li>Sublink3</li>
<li>Sublink4</li>
<li>Sublink5</li>
</ul>
</li>
<li><a class="has-sub-menu" href="http://google.com/nav">Link6</a>
<ul class="nav-lvl-2">
<li>Sublink1</li>
<li>Sublink2</li>
</ul>
</li>
</ul>
</nav>
</div>
</div>
And CSS:
.header {
position: fixed;
top: 0;
left: 0;
width: 100%;
background: #6ab014;
z-index: 100001;
height: 75px;
overflow: hidden;
-webkit-transition: height 0.3s;
-moz-transition: height 0.3s;
transition: height 0.3s;
}
/********* Disable link to open sub-menu **********/
.header .header-image a {
pointer-events: none;
cursor: pointer;
}
/* Stop header from overlapping container */
.container {
position: relative;
margin-top: 75px;
width: 100%;
}
.main {
position: block;
width: 90%;
max-width: 80em;
margin: 0 auto;
padding: 0 1.875em;
}
/********* Side Menu **********/
.header nav {
position: fixed;
left: 0px;
top: 75px;
background: #87cc33;
width: 330px;
height: 100%;
z-index: 1000;
overflow:auto;
/* Transitions */
-webkit-transition: all 0.3s ease;
-moz-transition: all 0.3s ease;
transition: all 0.3s ease;
}
.header nav ul
{
padding: 0;
margin: 0;
list-style-type: none;
}
/* Open menu CSS */
.menu.menu-open {
left: 0px;
}
/********* Navigation Sub-menus **********/
.menu .nav-lvl-2.sub-menu-open-mobile{
/* Max-height may have to change with more sublinks */
max-height: 1000px;
display: block;
opacity: 1;
}
.menu .nav-lvl-2 {
background: #a5e25b;
max-height: 0px;
display: none;
opacity: 0;
/* Transitions */
-webkit-transition: all .3s ease;
-moz-transition: all .3s ease;
transition: all .3s ease;
}
.menu .nav-lvl-2 a {
border-bottom: 1px solid #fff;
}
/********* Disable links to open sub-menu **********/
.has-sub-menu {
pointer-events: none;
cursor: pointer;
}
.menu li:hover {
cursor: pointer;
}
/********* Link CSS **********/
.menu a{
display: block;
color: #fff;
font-size: 1.1em;
font-weight: 300;
border-bottom: 1px solid #a5e25b;
padding: 1em;
text-decoration: none;
}
/******* Mobile dropdown arrow - down *********/
a.has-sub-menu:not(.sub-menu-open-mobile):before {
position: absolute;
content: "";
left: 290px;
width: 0;
height: 0;
border-left: 7px solid transparent;
border-right: 7px solid transparent;
border-top: 11px solid #fff;
margin-top: 7px;
}
/******* Mobile dropdown arrow - up *********/
a.has-sub-menu.sub-menu-open-mobile:before {
position: absolute;
content: "";
left: 290px;
width: 0;
height: 0;
border-left: 7px solid transparent;
border-right: 7px solid transparent;
border-bottom: 11px solid #fff;
margin-top: 7px;
}
/******* dropdown link css *********/
a.has-sub-menu:hover:before,
a.has-sub-menu:focus:before,
a.has-sub-menu:active:before {
border-color: transparent #730800;
}
a.has-sub-menu:hover:after,
a.has-sub-menu:focus:after,
a.has-sub-menu:active:after {
border-color: #730800;
}
Is there a way to solve this using CSS and not JQuery/Javascript?
How about using bottom: 0 instead of using height: 100%. Using height: 100% plus a top value will push it off the page.
Updated .header nav (JSFiddle)
.header nav {
position: fixed;
left: 0px;
top: 75px;
background: #87cc33;
width: 330px;
bottom: 0;
z-index: 1000;
overflow:auto;
/* Transitions */
-webkit-transition: all 0.3s ease;
-moz-transition: all 0.3s ease;
transition: all 0.3s ease;
}
Alternately, you could use height with calc.
height: calc(100% - 75px);
But the browser support is not as good with this option.