0% found this document useful (0 votes)
32 views

CSS Transitions

CSS transitions allow elements to smoothly transition between states over a specified duration. Transitions are defined using the transition property, which takes a list of the CSS properties to animate separated by commas, followed by the duration of the animation in seconds or milliseconds. Common transition properties include width, height, color, and transform. Additional transition properties like delay and timing-function control the delay before transition occurs and the speed of the transition over time. CSS transitions provide an easy way for designers to enhance interactivity and animations on a website.

Uploaded by

Kkimm Chii
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

CSS Transitions

CSS transitions allow elements to smoothly transition between states over a specified duration. Transitions are defined using the transition property, which takes a list of the CSS properties to animate separated by commas, followed by the duration of the animation in seconds or milliseconds. Common transition properties include width, height, color, and transform. Additional transition properties like delay and timing-function control the delay before transition occurs and the speed of the transition over time. CSS transitions provide an easy way for designers to enhance interactivity and animations on a website.

Uploaded by

Kkimm Chii
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

MMINTER

CSS Transitions
CSS Transitions Overview
● Introduction
● How does a transition work?
● Syntax
● Properties
● Examples
Introduction
● CSS transitions are an easy way for a designer to enhance
the interactivity of a design using animation.

WITHOUT TRANSITION WITH TRANSITION

A hover effect without a A transition property allows the


transition property immediately browser to smoothly animate or
toggles between two states. "tween" between two states.
How does a transition work?
Consider this example.
On hover, the scale
property of the object
changes from 1 to 1.5.

This makes the circle


grow in size when the
pointer is hovered over it.

This change in value


.circle { .circle:hover {
happens immediately.
transform: scale(1); transform: scale(1.5);
width: 150px; }
height: 150px;
background-color: #F13E0B;
border-radius: 50%;
}
How does a transition work?
After adding a transition
property, notice how the
scaling now happens
smoothly over time!

.circle { .circle:hover {
transform: scale(1); transform: scale(1.5);
width: 150px; }
height: 150px;
background-color: #F13E0B;
border-radius: 50%;
transition: transform 250ms;
}
How does a transition work?
This is how CSS transitions
work: by gradually
transitioning from one value
to another over time.

.circle { .circle:hover {
transform: scale(1); transform: scale(1.5);
width: 150px; }
height: 150px;
background-color: #F13E0B;
border-radius: 50%;
transition: transform 250ms;
}
Basic syntax
.sample-element {
transition: <property to animate> <time>;
}

A property could be almost anything that holds a The time describes how long the animation will
numeric value: width, height, margin, go on for. The higher the value, the longer or
padding, color, transform... slower it will take.

This can be expressed in seconds or


milliseconds (ex. 2s or 200ms)
Basic syntax
.change-width {
transition: width 250ms;
}

So in this example, the width of the element


with the class change-width would change
over 250 milliseconds, or a quarter of a second.
Basic syntax
.change-width {
width: 100px;
transition: width 250ms;
}

.change-width:hover {
width: 250px;
}
To determine the starting and ending width of
the element, we have to add some additional
CSS.
Combining transitions
It's also possible to have more than one property animate, like in the third example
here! Just use a comma to separate each transition rule.

nav a {
...
transition: height 500ms;
}

nav a {
...
transition: background-color 500ms;
}

nav a {
...
transition: height 500ms, background-color 500ms;
}

the comma
separator
Combining transitions
You can also split up the declaration like this. If there's only one value under
transition-duration, it will be used for all the properties declared under
transition-property.

nav a {
transition-property: height, background-color;
transition-duration: 500ms;
}
Transition properties
There are also other properties, like transition-delay. Notice how the
transition only plays if the cursor stays on the button for at least 250ms.

.circle {
transition-property: color, background-color, border;
transition-duration: 500ms;
transition-delay: 250ms;
}
adds
.circle:hover { delay!
color: #FFFFFF;
background-color: #00ad11;
border:12px solid;
}

.circle.blue:hover { border-color: #1a46c9; }

.circle.red:hover { border-color: #cf0a0a; }

.circle.orange:hover { border-color: #ff8400; }

.circle.violet:hover { border-color: #a32bff; }


Transition properties
Finally, there is transition-timing-function, which controls the rate of change throughout the
transition.

Note how the linear animation maintains a constant speed throughout. Ease-in starts out slow then
speeds up, while ease-out is the opposite, with a fast start and a slow end.

.ease { transition-timing-function: ease; }

.linear { transition-timing-function: linear; }

.ease-in { transition-timing-function: ease-in; }

.ease-out { transition-timing-function: ease-out; }


Sources
● https://www.tutorialspoint.com/cpanel/index.htm
● https://websitesetup.org/beginners-guide-to-cpanel/

You might also like