Reputation: 15925
WORKING SOLUTION:
ORIGINAL QUESTION:
I am trying to create a menu hover effect similar to the one found on the BBC website:
The top menu which creates a line at the bottom of the link being hovered over. I am trying to do something similar, but I want to line to be at the top.
I have created the following example, to show the problem I am experiencing:
<a href="#" class="menu_link">link 1</a>
<a href="#" class="menu_link">link 2</a>
<a href="#" class="menu_link">link 3</a>
a.menu_link{
height:50px;
display:block;
float:left;
margin-right:10px;
padding:0px 5px 0px 5px;
}
a.menu_link:hover{
border-top:5px solid black;
padding-top:5px;
}
When hovering over my example links, the line pushes the link down. I don't want this to happen, and I can't figure out how to stop it from happening.
Any suggestions?
Upvotes: 0
Views: 498
Reputation: 16673
Add this to your menu_link default css
border-top: 5px solid transparent;
So it ends up like this;
a.menu_link{
height:50px;
display:block;
float:left;
margin-right:10px;
padding:0px 5px 0px 5px;
border-top: 5px solid transparent;
}
If you want to keep the padding, you can set the box-sizing
to border-box
, but keep in mind that this is css3 and won't work in older browsers
a.menu_link{
height:50px;
display:block;
float:left;
margin-right:10px;
padding:0px 5px 0px 5px;
border-top: 5px solid transparent;
box-sizing: border-box;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
-ms-box-sizing: border-box;
-o-box-sizing: border-box;
}
Upvotes: 3
Reputation: 1791
Working example - http://jsfiddle.net/DPNLq/4/
.menu_link{
height:50px;
display:block;
float:left;
margin-right:10px;
padding:10px 5px 0px 5px;
}
a.menu_link:hover{
border-top:5px solid black;
padding-top:5px;
}
Upvotes: 0
Reputation: 2657
Match the top elements (padding and border) before the hover:
a.menu_link{
height:50px;
display:block;
float:left;
margin-right:10px;
padding:5px 5px 0px 5px;
border-top: 5px solid transparent;
}
Upvotes: 0
Reputation: 944010
Keep the border there all the time. Just change its colour. (From transparent
if you can't match a solid colour).
Upvotes: 4