Computer Science 318

Fundamentals of Web Design

Lab 16 Animations



Animation Properties

CSS Animations make it possible to animate transitions from one CSS style configuration to another. Animations consist of two components, a style describing the CSS animation and a set of keyframes that indicate the start and end states of the animation's style, as well as possible intermediate waypoints.



Specifies the name of the @keyframes at-rule describing the animation’s keyframes.



Configures the length of time that an animation should take to complete one cycle.



Configures the timing of the animation; that is, how the animation transitions through keyframes, by establishing acceleration curves.

Values for animation-timing-function:



Configures the delay between the time the element is loaded and the beginning of the animation sequence.



Configures the number of times the animation should repeat; you can specify infinite to repeat the animation indefinitely.

Values for animation-iteration-count:



Configures whether or not the animation should alternate direction on each run through the sequence or reset to the start point and repeat itself.

Values for animation-direction:



Configures what values are applied by the animation before and after it is executing.

Values for animation-fill-mode



Lets you pause and resume the animation sequence.

Values for animation-play-state:

    animation:fade-in 3s linear .2s infinite alternate forward;


Can be used a shorthand for the properties above in this order: animation-name, animation-duration, animation-timing-function, animation-delay, animation-iteration-count, animation-direction, animation-fill-mode, and animation-play-state. Commas are not need in between these values.

animation-name: fadeInOut, moveLeft300px, bounce;
animation-duration: 2.5s, 5s, 1s;
animation-iteration-count: 2, 1, 5;

Multiple animation can be applied to the same element, these are separated by commas.


@keyframes animations-name{

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.

In the example above there are three keyframes: from, 50%, and to.

At 0% the animation starts left at 0 pixels with no rotation. Then at 1 second or 50% of the animation it will be at 50 pixels from the left. Then at 100% of the animation or 2 seconds it will be at 100 pixels and rotate 90 degrees.

Though 50% doesn't have a rotation defined, if possible the keyframe will try to interpolate the value.


transform: scale(1.5) translate(2rem) rotate(10deg) skew(30deg, 180deg);

The transform CSS property lets you rotate, scale, skew, or translate an element. When applying multiple transforms to an element, multiple transform functions are place in one transform property.

Transform Functions






Experiment Create keyframes that use the move animation to move the square from left 0 to left 100%. Then add a new declaration for hovering on the square that pauses the animation.


<div class="square"></div>


.square{ animation:move 1s ease-in-out infinite alternate; position:fixed; width:2rem; height:2rem; background-color:yellow; left:0; top:50%; } body{ background-color:black; }


Experiment Try adding the transform property to the logo with a rotation of 260deg, a scale of 4, and translateX of 10rem.


<div class="logo"></div>


.logo{ position:fixed; background-image:url(; background-size:contain; background-repeat:no-repeat; width:4rem; height:4rem; }


Open GitHub Desktop (you may need to download the program again if the computers get wiped.)

Couple of things to check in GitHub Desktop.

With your cs-318 repository selected, Click open in Visual Studio code.

Create a new folder called lab16

Create a new file called index.html in the lab16 folder

Setup your HTML files

Create your stylesheet

Link your stylesheet to the HTML

Change Document in the <title> element to "Mars Rovers"

In the <body> add a <header> and a <main>

In the <header> add a <nav>

In the <nav> add four <a>. Leave href blank for now. We will be adding ids to create jump links later.

In the <main> add two <section>

In first <section> add:

<div> with id of "stars"

<div> with id of "stars2"

<div> with id of "stars3"

<div> with class of "rover"

In the rover <div> add the image:


Add the planet image with a class of "planet" (not in the rover div, but after it.)


<div> with class of "mars"

In mars div add <h1> "The Mars Rovers"

Lab 15 html setup

In second <section> add:

<h2> with id of "overview"





<h2> with id of "robots"


<div> with class of "robots"



Iframe below

<iframe src='' width='800' height='450' scrolling='no' frameborder='0' allowfullscreen></iframe>

<div> with class of "grid"

<h2> with id of "timeline"


<div> with class of "grid"

<h2> with id of "maps"


<div> with class of "maps"

Lab 16 section two content



background color #09021d margin 0 font color #fff font family


max-width 100%


background rgb(9,2,29)

background: linear-gradient(180deg, rgba(9,2,29,1) 0%, rgba(9,2,29,0) 100%);.
Hint: This will create a gradient background color

position fixed

width 100%

padding 1rem

Lab 16 header styles

header a

font color #fff

margin 1rem

header a:hover

font color #d15f44

Lab 16 navigation link styles

In HTML add class=headline to the first section


position relative
Hint: this will allow us to position all of the animation elements within the div based on the div's width and height

width: calc(100vw - 1rem);
Hint: VW- is viewwidths which is 1% of the viewport or browser's screen width

height 80vh
Hint: VH- is viewheights which is 1% of the viewport or browser's screen height

Hint: this will hid any elements that move outside of the div

padding 0


width 20rem

height 20rem

position absolute

display block

bottom 10.5rem

left 10%

Lab 15 rover sizing


width 5rem

height 5rem

position absolute

left 30%

Lab 15 planet css


position absolute

width 100%

height 10.5rem

background color #913a25

border-top 1rem solid #d15f44

bottom 0

Lab 16 mars css


content:url(); for the image below


width 6rem

height 6rem

position absolute

left 2.25rem

top 1.6rem

Lab 16 dish setup

.mars h1

margin-left 5rem

font-size 3rem

font-weight 900

Lab 16 H1 CSS


animation: rise 10s ease-in 1 forwards;
Hint: We are calling this animation rise, it will take 10s, it will ease-in to the animation, and will only happen once, and the animation will keep the values set by the last keyframe after the animation is complete.

@keyframes rise{}



Lab 16 planet animation


z-index 1

transform-origin:center bottom;
Hint: This will move the point that the dish rotates on from the top left to center bottom

Add an animation with:

setup the keyframes for the animation you just defined

Lab 16 dish rotating animation


z-index 1.
Hint: this will move the rover in front of the planet

Setup an animation with keyframes that will move the rover like the image below.
Hint: The animation uses six of the animation properties (name, duration, timing-function, delay, interation-count, and direction), and two keyframes.

Lab 16 rover animation


animation-play-state: paused;
Hint: this will make the rover stop if the cursor is hovering on it.

Download the following CSS file and add to lab 16 folder

In HTML add <link rel="stylesheet" href="stars.css">

Lab 16 stars css


With the new stars css you can no longer see the header. Add a z-index of 3


z-index 2

Lab 16 header z-index


padding 1rem


color #d15f44

margin-top 5rem

Lab 16 h2 and section css


display grid

grid-column-templates 1fr 1fr 1fr

gap 2rem

In the HTML

In the robots div add a <figure> around each image (3 total figures)

In each <figure> add a <figcaption> after each <img> with the following content

Back to CSS

.robots figure

justify-self center

Lab 16 robots CSS


display block

margin 1rem auto 3rem

max-width 100%

Lab 16 iframe css


display grid

grid-template-columns 1fr 1rem 1fr
Hint: The goal of the grid is to create two text columns (the 1frs) with a line down the center (the 1rem). We are going move the hr with grid-area to take up the entire center column.

.grid hr

grid-area 1/2/10/3

Lab 16 grid hr css

.grid p

margin 1rem

.grid h3

margin 1rem

justify-self right

Lab 16 grid p and h3 css

Back in HTML

In the maps div add a <figure> around each image (2 total figures)

In each <figure> add a <figcaption> after each <img> with the following content

Back in CSS


display grid

grid-template-columns 1fr 1fr

gap 2rem

Lab 16 Map CSS

figcaption, h3

transition:color .2s ease-in-out;

.figcaption:hover, h3:hover

font color #d15f44

Lab 16 figcaption css

Add @media (min-width:600px)


padding 1rem 5rem

Lab 16 Finished

Final Steps

Validate your HTML.

Lint your CSS at

Now look at GitHub Desktop. You should see all of your files listed out in the left column.

GitHub Desktop files listed

Now you are going to commit your changes.

With all of the files checked. Fill out the Summary field in the bottom left and then click Commit to main.
Committing is staging the files, so they can be pushed to the repository hosted at GitHub.

GitHub Desktop Summary field.

Now you want to push your changes to the Repository. Now if you access the repository from another computer Lab16 will be there. After you push in the top right of the nav it should say "Fetch Origin" instead of "Push Origin"

GitHub Push Origin

Your are Done with Lab16