Bounce Animation with HTML & CSS

Web Design & Web Development

Demo

Sponsored links

 

Code

HTML

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>Pure CSS Bounce 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="bounce">
          <div class="ball"></div>
          <div class="shadow"></div>
        </div>
        <h1>Pure CSS<br>Bounce 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: #47b1c8;
  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: 10px 0 0;
  color: #3d3935;
  font-weight: 600;
  font-size: 3rem;
  letter-spacing: 1px;
  text-align: center;
}
.bounce {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  position: relative;
  width: 250px;
  height: 300px;
}
.ball {
  position: absolute;
  top: 10px;
  left: 90px;
  z-index: 2;
  width: 70px;
  height: 70px;
  border-radius: 50%;
  background-image: url(ball.png);
  background-position: center;
  background-size: 70px 70px;
  background-repeat: no-repeat;
  content: '';
  animation: bounce 1s infinite;
}
.shadow {
  position: absolute;
  bottom: 8px;
  left: 98px;
  z-index: 1;
  transform: scale(1);
  width: 60px;
  height: 8px;
  border-radius: 50%;
  background-color: #2c3b62;
  content: '';
  animation: shadow 1s linear infinite;
}
@keyframes bounce {
  0% {
    top: 10px;
  }
  50% {
    top: 230px;
    width: 80px;
    height: 60px;
    background-size: 80px 60px;
  }
  100% {
    top: 10px;
  }
}
@keyframes shadow {
  0% {
    transform: scale(0);
  }
  48% {
    transform: scale(1);
  }
  100% {
    transform: scale(0);
  }
}
@media screen and (max-width: 480px) {
  #container {
    align-items: flex-start;
    height: auto;
    overflow-x: hidden;
    overflow-y: scroll;
  }
  .box {
    height: auto;
    padding: 20px 0;
  }
  .box h1 {
    font-size: 1.75rem;
  }
}