CSS Hover Border Without Re Sizing Image
Solution 1:
You have a constraint on the total height of the container for the anchor containing the image. When you add the border you are adding 5px to the height of the container, which will shrink the image since it is maintaining its aspect ratio to fill the smaller available height. Since margins are not considered when calculating the size of the container it is changing size. I changed it to change the size of the padding instead here.
.navbar-div a:hover {
border-bottom: 5px solid black;
padding-bottom: 5px;
}
You may consider trying a different, less complicated approach. Since you will always know your background color you could make the border invisible but always there by just changing the color as seen here.
Solution 2:
You can use :after
pseudo-element. Code:
.navbar-div a:hover:after {
content:"\a0";
display:block;
padding:2px 0;
line-height:1px;
border-bottom:2px solid #000;
}
Solution 3:
You must change the
.navbar-div a:hover img {
margin: -5px;
}
What it is doing is to shrink the space inside the DIV, so the image will shrink also.
Post a Comment for "CSS Hover Border Without Re Sizing Image"