Menu

1 / 3

Why Your Navbar Shifts When You Hover (And How to Fix It With CSS)

DEV Community: css·ilma fauziyah·3 days ago
#hrCl3ks3
#devtocss#devto#dev#ddd#font
Long article (746 words) — no AI summary yet.
Reading 0:00
15s threshold

I was building a website using a CMS, and the navbar had a pretty common hover effect: the menu items turned bold when you hovered over them.

Nothing fancy. Simple. Basic, I thought.

Here's a simplified version of how I built it:

<nav class = "navbar" > <a href = "#" class = "logo" > Navbar </a>

<div class = "nav-links" > <a href = "#" class = "nav-link" > Home </a> <a href = "#" class = "nav-link" > Products </a> <a href = "#" class = "nav-link" > Services </a> <a href = "#" class = "nav-link" > About </a> <a href = "#" class = "nav-link" > Contact </a> </div> </nav>

Enter fullscreen mode

Exit fullscreen mode

.navbar { display : flex ; align-items : center ; justify-content : space-between ; gap : 32px ; padding : 20px 24px ; background : white ; border : 1px solid #ddd ; border-radius : 8px ; }

.logo { font-size : 20px ; font-weight : 700 ; color : #222 ; text-decoration : none ; white-space : nowrap ; }

.nav-links { display : flex ; align-items : center ; gap : 24px ; }

.nav-link { color : #333…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.