Navbar — horizontal navigation bar
Logo on the left, links on the right. Sticky at the top. The most common UI element.
style.css
v3.1
style.css — the CSS rules
index.html — the HTML structure (what the CSS targets)
Live preview
updates as you type
🧠 How it works
display: flex + justify-content: space-between pushes logo left, links right. position: sticky + top: 0 — the navbar stays at the top when you scroll. Unlike fixed, it takes up space in the flow. z-index: 100 — navbar stays above other content. The ul is also a flex container (display: flex) so the li items sit in a row. gap: 0.5rem — space between links (modern alternative to margin-right on each li). transition: all 0.15s on the links — hover color/background fades in smoothly. active class — marks the current page. Use it in your templates: <a class="active">Home</a>.
✏️ Try these changes
-
Change position: sticky to position: fixed→ navbar floats over content — content slides under it (need padding-top on body) -
Change justify-content: space-between to center→ logo and links center together -
Change background: #1a1a1a to #a0c000→ navbar becomes green -
Change .navbar ul li a padding to 0.8rem 2rem→ links become wider -
Remove the box-shadow→ navbar loses its depth separator