css sticky header with nav bar
CSS
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {
margin: 0;
font-size: 28px;
font-family: Arial, Helvetica, sans-serif;
}
.header {
background-color: #f1f1f1;
padding: 30px;
text-align: center;
}
#navbar {
overflow: hidden;
background-color: #333;
}
#navbar a {
float: left;
display: block;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}
#navbar a:hover {
background-color: #ddd;
color: black;
}
#navbar a.active {
background-color: #4CAF50;
color: white;
}
.content {
padding: 16px;
}
.sticky {
position: fixed;
top: 0;
width: 100%;
}
.sticky + .content {
padding-top: 60px;
}
</style>
</head>
<body>
<div class="header">
<h2>Scroll Down</h2>
<p>Scroll down to see the sticky effect.</p>
</div>
<div id="navbar">
<a class="active" href="javascript:void(0)">Home</a>
<a href="javascript:void(0)">News</a>
<a href="javascript:void(0)">Contact</a>
</div>
<div class="content">
<h3>Sticky Navigation Example</h3>
<p>The navbar will stick to the top when you reach its scroll position.</p>
<p>Some text to enable scrolling.. Lorem ipsum dolor sit amet, illum definitiones no quo, maluisset concludaturque et eum, altera fabulas ut quo. Atqui causae gloriatur ius te, id agam omnis evertitur eum. Affert laboramus repudiandae nec et. Inciderint efficiantur his ad. Eum no molestiae voluptatibus.</p>
<p>Some text to enable scrolling.. Lorem ipsum dolor sit amet, illum definitiones no quo, maluisset concludaturque et eum, altera fabulas ut quo. Atqui causae gloriatur ius te, id agam omnis evertitur eum. Affert laboramus repudiandae nec et. Inciderint efficiantur his ad. Eum no molestiae voluptatibus.</p>
<p>Some text to enable scrolling.. Lorem ipsum dolor sit amet, illum definitiones no quo, maluisset concludaturque et eum, altera fabulas ut quo. Atqui causae gloriatur ius te, id agam omnis evertitur eum. Affert laboramus repudiandae nec et. Inciderint efficiantur his ad. Eum no molestiae voluptatibus.</p>
<p>Some text to enable scrolling.. Lorem ipsum dolor sit amet, illum definitiones no quo, maluisset concludaturque et eum, altera fabulas ut quo. Atqui causae gloriatur ius te, id agam omnis evertitur eum. Affert laboramus repudiandae nec et. Inciderint efficiantur his ad. Eum no molestiae voluptatibus.</p>
<p>Some text to enable scrolling.. Lorem ipsum dolor sit amet, illum definitiones no quo, maluisset concludaturque et eum, altera fabulas ut quo. Atqui causae gloriatur ius te, id agam omnis evertitur eum. Affert laboramus repudiandae nec et. Inciderint efficiantur his ad. Eum no molestiae voluptatibus.</p>
<p>Some text to enable scrolling.. Lorem ipsum dolor sit amet, illum definitiones no quo, maluisset concludaturque et eum, altera fabulas ut quo. Atqui causae gloriatur ius te, id agam omnis evertitur eum. Affert laboramus repudiandae nec et. Inciderint efficiantur his ad. Eum no molestiae voluptatibus.</p>
<p>Some text to enable scrolling.. Lorem ipsum dolor sit amet, illum definitiones no quo, maluisset concludaturque et eum, altera fabulas ut quo. Atqui causae gloriatur ius te, id agam omnis evertitur eum. Affert laboramus repudiandae nec et. Inciderint efficiantur his ad. Eum no molestiae voluptatibus.</p>
</div>
<script>
window.onscroll = function() {myFunction()};
var navbar = document.getElementById("navbar");
var sticky = navbar.offsetTop;
function myFunction() {
if (window.pageYOffset >= sticky) {
navbar.classList.add("sticky")
} else {
navbar.classList.remove("sticky");
}
}
</script>
</body>
</html>
Also in CSS:
- Title
- effetto fade con css
- Category
- CSS
- Title
- css rotate
- Category
- CSS
- Title
- flex-wrap: wrap
- Category
- CSS
- Title
- wordpress css admin not loading
- Category
- CSS
- Title
- css ios disable zoom
- Category
- CSS
- Title
- hr css mdn
- Category
- CSS
- Title
- background color css
- Category
- CSS
- Title
- scss gradient mixin
- Category
- CSS
- Title
- css text shadow not showing in mac chrome
- Category
- CSS
- Title
- how to change font in css
- Category
- CSS
- Title
- link css file in html
- Category
- CSS
- Title
- space width css
- Category
- CSS
- Title
- padding css shorthand
- Category
- CSS
- Title
- css text justify
- Category
- CSS
- Title
- table css
- Category
- CSS
- Title
- learn css animation
- Category
- CSS
- Title
- how to make a fullscreen button an an iframe
- Category
- CSS
- Title
- css flex property
- Category
- CSS
- Title
- pestañas dentro de una pagina web php
- Category
- CSS
- Title
- image cover css
- Category
- CSS
- Title
- background color using css
- Category
- CSS
- Title
- how to center in absolute position
- Category
- CSS
- Title
- css width calculation
- Category
- CSS
- Title
- how to link locally installed fonts to css
- Category
- CSS
- Title
- online bootstrap css file link
- Category
- CSS
- Title
- font face html
- Category
- CSS
- Title
- remove blue border on a input
- Category
- CSS
- Title
- print zend db select query to string
- Category
- CSS
- Title
- css ios media query
- Category
- CSS
- Title
- w3 link fontawesome
- Category
- CSS
- Title
- css transform size
- Category
- CSS
- Title
- add css to an html file
- Category
- CSS
- Title
- scss npm import
- Category
- CSS
- Title
- css select all elements except last css
- Category
- CSS
- Title
- css animations transform
- Category
- CSS
- Title
- make footer stick to bottom without overlap over other elements
- Category
- CSS
- Title
- vertical align text inside div
- Category
- CSS
- Title
- css hiddden
- Category
- CSS
- Title
- how to give a div placeholder text
- Category
- CSS
- Title
- gradient image css
- Category
- CSS
- Title
- font color css
- Category
- CSS
- Title
- scss media query
- Category
- CSS
- Title
- how to print hello world with css
- Category
- CSS
- Title
- css box shadow not on bottom
- Category
- CSS
- Title
- css transition transform
- Category
- CSS
- Title
- aliceblue hex
- Category
- CSS
- Title
- how to add css to alt attribute text
- Category
- CSS
- Title
- hidden vs visible
- Category
- CSS
- Title
- css hide element
- Category
- CSS
- Title
- css align center
- Category
- CSS
- Title
- amazon type search box html css
- Category
- CSS
- Title
- css grid tutorial
- Category
- CSS
- Title
- select even child css
- Category
- CSS
- Title
- kotlin iterate array
- Category
- CSS
- Title
- font size css
- Category
- CSS
- Title
- have unordered list horizontal css
- Category
- CSS
- Title
- css italic text
- Category
- CSS
- Title
- orientation css max and min width media query
- Category
- CSS
- Title
- background gradient vertical css
- Category
- CSS
- Title
- adjecent sibling selectors
- Category
- CSS
- Title
- how to cover full image in css
- Category
- CSS
- Title
- breakpoint bootstrap
- Category
- CSS
- Title
- tint image with background color css
- Category
- CSS
- Title
- center vertically and horizontally css
- Category
- CSS
- Title
- ordered list indent
- Category
- CSS
- Title
- !important in css
- Category
- CSS
- Title
- css keep background image from scrolling
- Category
- CSS
- Title
- css styling
- Category
- CSS
- Title
- on hover css
- Category
- CSS
- Title
- line-height not working
- Category
- CSS
- Title
- print media css
- Category
- CSS
- Title
- font weight css
- Category
- CSS
- Title
- css selectors w3schools
- Category
- CSS
- Title
- css center vertically
- Category
- CSS
- Title
- como fazer listrada css
- Category
- CSS
- Title
- use PurifyCSS with hugo
- Category
- CSS
- Title
- text animation css
- Category
- CSS
- Title
- comentarios en archivo scss
- Category
- CSS
- Title
- flexbox align center vertically
- Category
- CSS
- Title
- css queryselector
- Category
- CSS
- Title
- dropdown menu css
- Category
- CSS
- Title
- css note
- Category
- CSS
- Title
- card syntax html
- Category
- CSS
- Title
- how to use hover in css
- Category
- CSS
- Title
- css animations examples
- Category
- CSS
- Title
- hwo to use flexbox to make a nav bar
- Category
- CSS
- Title
- stop text from wrapping
- Category
- CSS
- Title
- css style scrollbar
- Category
- CSS
- Title
- convert sass to css
- Category
- CSS
- Title
- adding background image css
- Category
- CSS
- Title
- css to hide scrollbar
- Category
- CSS
- Title
- get rid of arrows number input
- Category
- CSS
- Title
- css hover
- Category
- CSS
- Title
- tint image css
- Category
- CSS
- Title
- css vertical center
- Category
- CSS
- Title
- nth-child(2n+1)
- Category
- CSS
- Title
- cursor as image css
- Category
- CSS
- Title
- css focus border radius
- Category
- CSS
- Title
- laavel relation through morph
- Category
- CSS
- Title
- DevTools failed to load SourceMap: Could not load content for bootstrap.min.css.map
- Category
- CSS