The problem
You want a navigation header that sticks to the top and adds a shadow when scrolling.
The solution
.sticky-header {
position: sticky;
top: 0;
background: rgba(13, 17, 38, 0.95);
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
padding: 16px 24px;
z-index: 100;
transition: box-shadow 0.3s ease;
}
.sticky-header.scrolled {
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}
/* Alternative: Pure CSS shadow on scroll */
.sticky-header-auto {
position: sticky;
top: -1px;
padding-top: calc(16px + 1px);
background: #0d1126;
z-index: 100;
}
.sticky-header-auto::before {
content: '';
position: absolute;
top: 100%;
left: 0;
right: 0;
height: 20px;
background: linear-gradient(
to bottom,
rgba(0, 0, 0, 0.2),
transparent
);
opacity: 0;
transition: opacity 0.3s;
pointer-events: none;
}
.sticky-header-auto.stuck::before {
opacity: 1;
}See it live
Put it to work
<header class="sticky-header">
<nav>
<a href="/">Logo</a>
<ul>
<li><a href="#home">Home</a></li>
<li><a href="#about">About</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
</nav>
</header>Worth knowing
Add .scrolled class with JavaScript on scroll, or use IntersectionObserver for better performance.