Files
30-seconds-of-code/snippets/image-hover-rotate.md
Isabelle Viktoria Maciohsek 2487083cf1 Bake dates into snippets
2021-06-13 19:41:39 +03:00

821 B

title, tags, firstSeen, lastUpdated
title tags firstSeen lastUpdated
Image rotate on hover animation,visual,intermediate 2020-04-20T18:36:11+03:00 2020-12-30T15:37:37+02:00

Creates a rotate effect for the image on hover.

  • Use scale and rotate when hovering over the parent element (a <figure>) to animate the image, using the transition property.
  • Use overflow: hidden on the parent container to hide the excess from the image transformation.
<figure class="hover-rotate">
  <img src="https://picsum.photos/id/669/600/800.jpg"/>
</figure>
.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);
}