View on GitHub

Code Fellows reading notes

A repository for organizing notes from my learning.

CSS Transforms, Transitions and Animations

Transforms

Source: shayhowe HTML/CSS Lesson 7

CSS3 introduced the transform property, which allows us to change the shape of elements in either 2d or 3d. The syntax is simply transform: value.

2D transforms

2d transforms work on the x and y axes of the page, and include the following:

3D transforms

3D transforms are used to alter elements on 3 axes, and include:

Transitions and Animations

Source: shayhowe HTML/CSS Lesson 8

Transitions

For a transition to take place, an element must have a change in state, such as :hover :focus :active etc. The property to be transitioned should be specified using transition-property.

transition-duration and transition-timing-function affect the speed of the transition.

transition-delay can be used to add a delay to a transition.

Animations

Animations are created using the @keyframes rule in CSS.

/* example from source:*/
@keyframes slide {
  0% {
    left: 0;
    top: 0;
  }
  50% {
    left: 244px;
    top: 100px;
  }
  100% {
    left: 488px;
    top: 0;
  }
}

By using animatio-name and animation-duration properties, we can add animations that we define using @keyframes to an element. The keyframes act as points within the provided duration, up to 100%. The same animation can be used with multiple durations, but will appear to be faster or slower depending on how much time the animation is given to complete.