Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spin or rotate an image on hover

I want to find out how to make a spinning or rotating image when it is hovered. I would like to know how to emulate that functionality with CSS on the following code :

img {    border-radius: 50%;  }
<img src="http://i.imgur.com/3DWAbmN.jpg" />
like image 328
user3597950 Avatar asked May 16 '14 12:05

user3597950


People also ask

How do you rotate an image in CSS?

Rotating an image using CSS Once the CSS code is applied to your . css file, stylesheet, or <style> tags, you can use the CSS class name in any of your image tags. To rotate an image by another measure of degrees, change the "180" in the CSS code and <img> tag to the degree you desire.

What is hover effect on image?

Hover CSS lets you add hover effects to any element, such as a button, link or image. The effects include 2D transitions, background transitions, border, Shadow and Glow transitions, and more. The library is available in CSS, Sass, and LESS.

How do I rotate an image in stackoverflow?

add "style="z-index: 1" to the object you're rotating and style="z-index: 2" (or any number higher than 1) to the text or whatever you want to display on top.


1 Answers

You can use CSS3 transitions with rotate() to spin the image on hover.

Rotating image :

img {   transition: transform .7s ease-in-out; } img:hover {   transform: rotate(360deg); }
<img src="https://i.stack.imgur.com/BLkKe.jpg" width="100" height="100"/>

Here is a fiddle DEMO


More info and references :

  • a guide about CSS transitions on MDN
  • a guide about CSS transforms on MDN
  • browser support table for 2d transforms on caniuse.com
  • browser support table for transitions on caniuse.com
like image 76
web-tiki Avatar answered Sep 21 '22 10:09

web-tiki