I'm new to HTML/CSS and am building a simple test site. Currently, I am trying to get sticky positioning to work. Specifically, I have a title/logo area with a toolbar underneath. As you scroll down, I want the title to scroll away, but the toolbar to scroll until it reaches the top of the page, where it'll remain.
I've tried removing all size adjustments, padding, and margins. I read that height adjustments can cause problems, so I thought I'd try all of those. I don't have any overflow either. I also tried putting the sticky position on all of the different elements. It's still not working and I don't understand why.
Any advice would be greatly appreciated. Thanks!
My code:
h1 {
background-color: lightblue;
text-align: center;
}
.toolbar {
border: 3px double black;
background-color: coral;
padding: 5px;
text-align: center;
width: 80%;
max-width: 650px;
margin: auto;
position: sticky;
top: 0px;
margin: auto;
}
main {
height: 200vh;
}
a {
display: inline-block;
color: black;
background-color: lightblue;
list-style-type: none;
border: 1px solid black;
width: 100px;
font-size: 20px position:sticky;
}
a:link {
text-decoration: none;
color: red;
}
<header>
<h1>Title Area</h1>
<h2>"Awesome Tagline!"</h2>
<hr>
</header>
<nav>
<ul class="toolbar">
<a href="">
<li>Home</li>
</a>
<a href="">
<li>About</li>
</a>
<a href="">
<li>Menu</li>
</a>
<a href="">
<li>Other</li>
</a>
</ul>
</nav>
<main></main>