Reputation: 23208
I am creating a menu bar where I need to show border on hover. but adding border is disturbed the layout.
How can add border without affecting layout.
Upvotes: 1
Views: 237
Reputation: 23208
Instead of adding outline or manipulating height I change the margin of current hovered element.
Upvotes: 0
Reputation: 10246
It depends on the border width, if you are using 1 px border then reduce 2 px from width and 2 px from height for each element for which you are adding border.
Upvotes: 2
Reputation: 26753
You have two choices.
Probably best is to add a border even when it's not on hover, but set the color to transparent
(or to the background color). Then in the hover only change the background-color:
, but not the size or existence of the border.
Or you can use outline:
- but check browser support for it first.
Upvotes: 6