CSS Animations - Transforms and Transitions
Overview
CSS is normally applied instantly when rendered. CSS animations using @keyframes, transitions, and the transform property are used to control state animation from one to another state of a selected element, including its pseudo-classes.
"The @keyframes CSS at-rule controls the intermediate steps in a CSS animation sequence by
defining
styles for keyframes (or waypoints) along the animation sequence. This gives more control over
the
intermediate steps of the animation sequence than transitions." - MDN
Prepare
- Reference Only: 📑CSS Transform - MDN
- Reference Only: 📑CSS Transition - MDN
- Read: 📃CSS Animations - w3schools.com
Activity Instructions
- Create a valid HTML file that contains one <div> element with a class of "box".
- The content of the
div
with a class ofbox
is "WDD 330". - Create a supporting CSS file and link it to the HTML file.
- In the CSS file, create a rule for the <body> element that will center the
<div> in the the <body> horizontally and vertically.
Example
body { display: flex; align-items: center; justify-content: center; height: 100vh; margin: 0; }
- Style the
box
class to a shape of your own design with some basic background color and dimensions. - Create a
@keyframes
rule namedmyanima
with at least three animation points that transform and that changes one other property.Example
@keyframes myanima { 0% { transform: translateY(0); background-color: #abe; } 50% { transform: translateX(200px) translateY(-100px); background-color: #24A; color: #fff; } 100% { transform: translateX(-100px) translateY(-100px); background-color: #57D; } }
- In the
.box
CSS rule, apply an animation declaration that uses yourmyanima
keyframe animation schema.Example
animation: myanima 3s infinite alternate;
- Be creative and make this your own.
- Share your animation with the class by posting a link to your public code (GitHub or CodePen) in the General forum.
- Example: CSS Animation - codepen.io