Reputation: 125
I have a DIV with this CSS on hover:
.card:hover {
box-shadow: 5px 5px 20px #c4c4c4;
margin-top: -5px;
margin-left: -5px;
}
And inside this div, I have an image with this CSS:
.card .avatar {
border-radius: 100px;
margin-top: -30px;
margin-left: 10px;
}
The problem is that the image seems to be "shaking" a bit when the transition occurs.
Here´s the fiddle: https://jsfiddle.net/zudvv4cv/2/
Upvotes: 1
Views: 1926
Reputation: 1043
Use the transform property instead of margin
.card:hover {
box-shadow: 5px 5px 20px #c4c4c4;
transform:translate(-5px, -5px);
}
Make sure you have used all proper prefixes
.card:hover {
box-shadow: 5px 5px 20px #c4c4c4;
-webkit-transform:translate(-5px, -5px);
transform:translate(-5px, -5px);
}
Sample https://jsfiddle.net/zudvv4cv/4/
Upvotes: 2
Reputation: 14257
Just use transform: translate(x,y)
to do the transition, its ignoring the position of sourrounding elements.
transform: translate(-5px, -5px);
Upvotes: 1