From dbbec84267ff9dfe42505d6e51eeac2b71a34e0c Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Mon, 20 Apr 2020 18:36:11 +0300 Subject: [PATCH] Add image rotate on hover effect --- snippets/image-hover-rotate.md | 39 ++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 snippets/image-hover-rotate.md diff --git a/snippets/image-hover-rotate.md b/snippets/image-hover-rotate.md new file mode 100644 index 000000000..c515b3cfe --- /dev/null +++ b/snippets/image-hover-rotate.md @@ -0,0 +1,39 @@ +--- +title: Image rotate on hover +tags: animation,visual,intermediate +--- + +Creates a rotate effect for the image on hover. + +```html +
+ +
+``` + +```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); +} +``` + +#### Explanation + +- 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. + +#### Browser support