So, I've been trying to create a navigation bar, using HTML and CSS that will "stick" to the top of the page, even when the user scrolls down.
Used the position: sticky
tag to do it. The problem is, I am not able to fix the div at the top of the page.
That's my CSS:
.bar {
position:sticky;
top:0;
color: white;
background-color: black
}
p {
display: inline;
}
... and my HTML code:
<nav class="bar">
<p>Home</p>
<p>Info</p>
<p>Contact Us</p>
</nav>
The sticky
propriety works. The problem is, bar
is not "fixed" at the top of the page. I know. Not the best word used for the explanation.
I just want it to be there, without any margins. Tried to reduce from the body's padding/margins but didn't work. What can I do?
Another question: what does really top:0
do? The position:sticky
propriety doesn't work without it and I want to know why.
` elements, to make the page scrollable. That's all. I don't think I need to mention my whole code.
– Apr 30 '19 at 23:23