I am trying to make my nav bar move with the page but stick to the top if the user scrolls down. Could anyone provide any examples or how to? Much appreciated. (I'm hopeless in any other language). I tried using the css sticky but it didn't work.
<div class="headercss">
<div class="headerlogo"></div>
<div class="nav">
<ul>
<li><a href="#home"> <br>BLINK</a></li>
<li><a href="#news"><br>ADVERTISING WITH BLINK</a></li>
<li><a href="#contact"><br>EDUCATING WITH BLINK</a></li>
<li><a href="#about"><br>ABOUT US</a></li>
</ul>
</div>
</div>
/* www..com
Blinx Service
Created by Pierre Chedraoui
(c) Copyright 2015
*/
/* BODY */
body {
margin: 0px;
background-color: #000000;
height: 2000px;
}
/* 1. HEADER */
.headercss {
width: auto;
height: 320px;
background-color: #000000;
position: relative;
}
.headerlogo {
width: auto;
height: 250px;
background-color: #272727;
position: relative;
}
.nav {
width: auto;
height: 70px;
background-color: #272727;
position: relative;
overflow: hidden;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
float:left;
width:100%;
overflow: hidden;
}
li {
float: left;
width:25%;
min-width: 243px;
overflow: hidden;
}
a:link, a:visited {
display: block;
height: 68px;
min-width: 243px;
font-size: 12px;
color: #FFFFFF;
border-right: 1px solid #000000;
border-top: 1px solid #000000;
background-color: #272727;
text-align: center;
text-decoration: none;
font-family: 'Raleway', Arial;
letter-spacing: 2pt;
line-height: 200%;
overflow: hidden;
}
a:hover, a:active {
background-color: #242424;
}
CSS:
Attribute
position: fixed
will keep it stuck, while other content will be scrollable. Don't forget to setwidth:100%
to make it fill fully to the right.Example
Just use
z-index
CSS property as described in the highest liked answer and the nav bar will stick to the top.Example:
Just Call this code and call it to your nave bar for sticky navbar
You can do it with CSS only by creating your menu twice. It's not ideal but it gives you the opportunity have a different design for the menu once it's on top and you'll have nothing else than CSS, no jquery. Here is an example with DIV (you can of course change it to NAV if you prefer):
And then have the following CSS:
Here is a fiddle for you to see: https://jsfiddle.net/brghtk4z/1/
Give headercss position fixed.
Then give the content container a 320px padding-top, so it doesn't get behind the header.