codeburst

Bursts of code to power through your day. Web Development articles, tutorials, and news.

Follow publication

Tutorial: Make a Bouncing Ball Entirely with CSS

Brandon Morelli
codeburst
Published in
3 min readAug 24, 2017

What we’ll be making

Project Setup

<div class="ball"></div>
body {
display: flex; /* Use Flexbox */
justify-content: center; /* Center Horizontally */
}
.ball {
width: 100px;
height: 100px;
border-radius: 50%; /* Turns a square into a circle */
background-color: #FF5722; /* Sets color to Orange */
}

Creating our Keyframe

@keyframes nameOfAnimation {
/* do stuff */
}
@keyframes bounce {
from { /* start */ }
to { /* end */ }
}
@keyframes bounce {
from { transform: translate3d(0, 0, 0); }
to { transform: translate3d(0, 200px, 0); }
}

Run The Keyframe

.ball {
/* ... */
animation: bounce 0.5s;
animation-direction: alternate;
animation-iteration-count: infinite;
}
.ball {
/* ... */

animation: bounce 0.5s cubic-bezier(.5,0.05,1,.5);
}

Where can I learn more?

Closing Notes

If this post was helpful, please click the clap 👏button below a few times to show your support! ⬇⬇

Published in codeburst

Bursts of code to power through your day. Web Development articles, tutorials, and news.

Written by Brandon Morelli

Creator of @codeburstio — Frequently posting web development tutorials & articles. Follow me on Twitter too: @BrandonMorelli

Responses (6)

Write a response