rotate image on hover css code example

Example 1: image rotate with css

div {
  width: 80px;
  height: 80px;
  background-color: skyblue;
}

.rotated {
  transform: rotate(45deg); /* Equal to rotateZ(45deg) */
  background-color: pink;
}

Example 2: rotate background image css

.theWholeElement{
  transform: rotate(30deg);
}

.justTheBackground{
  position: relative;
  overflow: hidden;
}

.justTheBackground::before{
  content: "";
  position: absolute;
  width: 200%;
  height: 200%;
  top: -50%;
  left: -50%;
  z-index: -1;
  background: url(background.png) 0 0 repeat;
  transform: rotate(30deg);
}

Tags:

Css Example