CSS3 Transitions

Designing, Defining, and Triggering CSS3 Transitions without Custom Libraries

Zoom

Zoom recording - starts at 01:00

Links

Properties

Must specify element to be transitioned and duration. You can specify multiple elements and duration times. A comma must be inserted between multiple elements. Elements only change from beginning state to ending state with no in-between.

transition: width 2s, height 4s;

Shorthand

transition: [transition-property] [transition-duration] [transition-timing-function] [transition-delay];

Speed Curve of the Transition

Cubic-bezier

W3schools states "A Cubic Bezier curve is defined by four points P0, P1, P2, and P3. P0 and P3 are the start and the end of the curve and, in CSS these points are fixed as the coordinates are ratios. P0 is (0, 0) and represents the initial time and the initial state, P3 is (1, 1) and represents the final time and the final state.".

Syntax: cubic-bezier(x1,y1,x2,y2)

Transition + Transform

You can do a transform at the same time you are doing a transition.

Examples

Shrinking Box

Click red box and hold to see transition.

#rolling-box {
    width: 200px;
    height: 200px;
    background-color: maroon;
    transition: width 3s, height 3s, background-color 3s, border-radius 2s, transform 3s;
    transform: rotate(0deg);
}

#rolling-box:active {
    width: 50px;
    height: 50px;
    background-color: #3c76a6;
    border-radius: 50%;
    transform: rotate(45deg);
}

Hidden text

Hover over gray box to see transition.

What is Lorem Ipsum?

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.

#hidden-content {
    height: 30px;
    width: 300px;
    background-color: #bababa;
    color: #fff;
    transition: height 0.5s;
    overflow: hidden;
}
#hidden-content:hover {
    height: 180px;
}