Skip to Content
Creating Web Animations
book

Creating Web Animations

by Kirupa Chinnathambi
March 2017
Beginner content levelBeginner
210 pages
4h
English
O'Reilly Media, Inc.
Content preview from Creating Web Animations

Chapter 3. Introduction to CSS Transitions

When you’re interacting with UIs, a lot of the animations you’ll see won’t be of the CSS animation kind with its predefined keyframes. They will instead be reactions to the things you are doing. Examples of such reactions include a link underlining when you hover over it, a menu flying in when you tap on a button, or a text element getting bigger when it has focus. For animating these kinds of behaviors, you will use CSS transitions.

To better understand CSS transitions, let’s take a moment to see one in action on our friendly hexagon shape:

Notice that the image smoothly scales up and rotates when your mouse cursor is over it. It then smoothly scales and rotates back to its original state when your mouse cursor goes elsewhere. All of this is made possible thanks to the magic of CSS transitions, and in the following sections, you’ll learn the basics of how to use them.

Creating a Simple Transition

Just like with CSS animations earlier, the way you’ll learn about CSS transitions is simple. We are going to dive head first and just use them. The first thing we’ll need to do is create a new HTML document and add the following things into it:

<!DOCTYPE html>
<html>
 
<head>
  <title>CSS Transitions!</title>
 
  <style>
    #container {
      width: 100%;
      height: 290px;
      background-color: #EEE;
 
      display: flex ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Web Animation using JavaScript: Develop and Design

Web Animation using JavaScript: Develop and Design

Julian Shapiro
Using SVG with CSS3 and HTML5

Using SVG with CSS3 and HTML5

Amelia Bellamy-Royds, Kurt Cagle, Dudley Storey

Publisher Resources

ISBN: 9781491957509Errata Page