CSS Spin Animation

12/10/2020

Demo

Full Screen

Code

HTML

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>CSS Spin Animation</title>
    <link rel="stylesheet" type="text/css" href="https://demo.plantpot.works/assets/css/normalize.css">
    <link rel="stylesheet" href="https://use.typekit.net/opg3wle.css">
    <link rel="stylesheet" type="text/css" href="style.css">
  </head>
  <body>
    <div id="container">
      <div class="box">
        <div class="windmill">
          <img src="windmill.svg" alt="windmill">
        </div>
        <h1>CSS Spin Animation</h1>
      </div>
    </div>
  </body>
</html>

CSS

@charset "utf-8";
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
html {
  font-size: 16px;
}
body {
  background-color: #2c5d48;
  font-family: futura-pt, sans-serif;
  -webkit-tap-highlight-color: rgba(0,0,0,0);
}
#container {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100vh;
}
.box {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  width: 100%;
  max-width: 720px;
  height: 100vw;
  max-height: 720px;
  padding: 20px;
}
.box h1 {
  margin: 30px 0 0;
  color: #fff;
  font-weight: 600;
  font-size: 3rem;
  letter-spacing: 1px;
  text-align: center;
}
.windmill {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  position: relative;
  width: 250px;
  height: 250px;
}
.windmill::before {
  position: absolute;
  bottom: 0;
  left: 115px;
  z-index: -1;
  width: 16px;
  height: 150px;
  background-color: #F1F9FF;
  content: '';
}
.windmill img {
  width: 200px;
  animation: spin 8s linear infinite;
}
@keyframes spin {
    from {
      transform: rotate(0);
    }
    to {
      transform: rotate(360deg);
    }
}
@media screen and (max-width: 480px) {
  #container {
    align-items: flex-start;
    height: auto;
    overflow-x: hidden;
    overflow-y: scroll;
  }
  .box {
    height: 400px;
    padding: 20px 0;
  }
  .box h1 {
    font-size: 1.5rem;
  }
}