1

I've been trying to make a navigation bar with small images which respond(by margin 10px from the top) when you hover over them. I applied the hover effects via a class Selector, however when I hover over one image the rest of them respond as well. So, can I correct this with the class Selector?

Here's the html side.

<a href=""><img class="menu" src="weight.png" /></a>
<a href=""><img class="menu" src="height.png" /></a>

Here's the css:

.menu{
    height:100px;
    width:100px; 
    transition:all 0.3s ease-in; margin-left:15px; 
    margin-top:5px;
}
.menu:hover{
    margin-top:15px;
    transition:all 0.3 ease-in;
}

Thank you for your help.

1 Answer 1

1

The default vertical alignment for inline content is "baseline". This means that your images by default stick to the bottom of your a elements. To fix this, you simply need to set the vertical alignment on your img elements to "top":

.menu {
    ...
    vertical-align: top;
}

JSFiddle demo.

Sign up to request clarification or add additional context in comments.

1 Comment

I don't quite get why it works, but it works. Thank you very much!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.