Reputation: 10189
So I have created a simple animation using CSS which is that when I hover over an image the margin of the image decreases so as to give a going up effect but the problem coming is that when I change the margin, all the things beneath it also move. How can I only move the image and not the whole?
CSS:
.down_arrow {
margin: 15px;
-webkit-transition: margin 0.5s ease-out;
-moz-transition: margin 0.5s ease-out;
-o-transition: margin 0.5s ease-out;
}
.down_arrow:hover {
margin-top: 2px;
}
HTML:
<div class="row text-center" style="margin-top: 30px;">
<img src="img/down_arrow.png" class="down_arrow" onclick="goToByScroll('ideas_section');" />
</div>
Here's what's happening: jSFiddle.
Upvotes: 1
Views: 3707
Reputation: 1810
Add au div with à fixed height arroud the img.
<div class="row text-center" style="margin-top: 30px; height: 100px;">
<img src="img/down_arrow.png" class="down_arrow" onclick="goToByScroll('ideas_section');" />
</div>
Upvotes: 2
Reputation: 78710
Just adjust the bottom margin to compensate:
.down_arrow:hover {
margin-top: 2px;
margin-bottom: 28px;
}
Upvotes: 0
Reputation: 7218
here is an updated fiddle
. appropriately set the bottom padding/margin too on hover
Upvotes: 1