<div class="container">
  <p>
    Hover over the container to apply the animations to the elements.
  </p>
  <div class="module">
    <p><code>none</code></p>
    <div class="wrapper">
      <div class="element element-1"></div>
    </div>
  </div>
  <div class="module">
    <p><code>forwards</code></p>
    <div class="wrapper">
      <div class="element element-2"></div>
    </div>
  </div>
  <div class="module">
    <p><code>backwards</code></p>
    <div class="wrapper">
      <div class="element element-3"></div>
    </div>
  </div>
  <div class="module">
    <p><code>both</code></p>
    <div class="wrapper">
      <div class="element element-4"></div>
    </div>
  </div>
</div>
body {
  background-color: #F5F5F5;
  color: #555;
  font-size: 1.1em;
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
}

hr {
  margin: 50px 0;
}

.container {
  margin: 40px auto;
  max-width: 800px;
  background-color: white;
  padding: 50px;
  border: 1px solid #aaa;
}

.module {
  width: 150px;
  display: inline-block;
}

.wrapper {
  width: 100px;
  height: 100px;
  border-radius: 5px;
  border: 1px dashed grey;
  display: inline-block;
}

.element {
  width: 100px;
  height: 100px;
  border-radius: 5px;
  background-color: purple;
  -webkit-transform-origin: bottom left;
  -ms-transform-origin: bottom left;
  transform-origin: bottom left;
}

.container:hover .element {
  -webkit-animation-name: rotate;
  animation-name: rotate;
  -webkit-animation-duration: 1s;
  animation-duration: 1s;
  -webkit-animation-timing-function: cubic-bezier(.18, 1.03, .5, 1.62);
  animation-timing-function: cubic-bezier(.18, 1.03, .5, 1.62);
}

.element-2 {
  -webkit-animation-fill-mode: forwards;
  animation-fill-mode: forwards;
}

.element-3 {
  -webkit-animation-delay: 1s;
  animation-delay: 1s;
  -webkit-animation-fill-mode: backwards;
  animation-fill-mode: backwards;
}

.element-4 {
  -webkit-animation-delay: 1s;
  animation-delay: 1s;
  -webkit-animation-fill-mode: both;
  animation-fill-mode: both;
}

@-webkit-keyframes rotate {
  0% {
    background-color: orange;
    -webkit-transform: rotate(0deg);
    transform: rotate(0deg);
  }
  100% {
    -webkit-transform: rotate(90deg);
    transform: rotate(90deg);
    background-color: #0099CC;
  }
}

@keyframes rotate {
  0% {
    background-color: orange;
    -webkit-transform: rotate(0deg);
    transform: rotate(0deg);
  }
  100% {
    -webkit-transform: rotate(90deg);
    transform: rotate(90deg);
    background-color: #0099CC;
  }
}