Creates a rotate effect for the image on hover.
- Use
scale
androtate
when hovering over the parent element (afigure
) to animate the image, using thetransition
property. - Use
overflow: hidden
on the parent container to hide the excess from the image transformation.
预览
HTML
<figure class="hover-rotate">
<img src="https://i.picsum.photos/id/669/600/800.jpg"/>
</figure>
CSS
.hover-rotate {
overflow: hidden;
margin: 8px;
min-width: 240px;
max-width: 320px;
width: 100%;
}
.hover-rotate img {
transition: all 0.3s;
box-sizing: border-box;
max-width: 100%;
}
.hover-rotate:hover img {
transform: scale(1.3) rotate(5deg);
}
翻译自:https://www.30secondsofcode.org/css/s/image-hover-rotate