Transitions Flashcards
What does the transition-property
CSS property do?
The transition-property
CSS property specifies which CSS properties should have transition effects applied to them when their values change.
“transition-property - CSS: Cascading Style Sheets | MDN” (developer.mozilla.org). Retrieved April 26, 2023.
What is the syntax of the transition-property
CSS property?
transition-property: property-1, property-2, ...;
Values
-
all
: Applies transitions to all properties that can be animated. -
none
: No transitions are applied.
Example values: all
, width
, background-color
, none
.
“transition-property - CSS: Cascading Style Sheets | MDN” (developer.mozilla.org). Retrieved April 26, 2023.
What does the transition-duration
CSS property do?
The transition-duration
CSS property sets the length of time a transition animation should take to complete. By default, the value is 0s
, meaning that no animation will occur.
“transition-duration - CSS: Cascading Style Sheets | MDN” (developer.mozilla.org). Retrieved April 26, 2023.
What is the syntax of the transition-duration
CSS property?
transition-duration: time-1, time-2, ...;
Values
- The time values can be given in seconds (e.g.,
2s
) or milliseconds (e.g.,2000ms
).*
Example values: 0.5s, 300ms
“transition-duration - CSS: Cascading Style Sheets | MDN” (developer.mozilla.org). Retrieved April 26, 2023.
What does the transition-timing-function
CSS property do?
The transition-timing-function
CSS property specifies how the intermediate values of a CSS transition are calculated, essentially defining the “easing” function for the transition.
“transition-timing-function - CSS: Cascading Style Sheets | MDN” (developer.mozilla.org). Retrieved April 26, 2023.
What is the syntax of the transition-timing-function
CSS property?
transition-timing-function: function-1, function-2, ...;
Values
-
linear
: Transition occurs at a constant speed. -
ease
: Starts slow, accelerates, then ends slowly. -
ease-in
: Starts slow and accelerates. -
ease-out
: Starts fast and decelerates. -
ease-in-out
: Starts slow, accelerates, then decelerates. -
cubic-bezier(n,n,n,n)
: Define a custom easing function using a cubic Bézier curve with control points. -
step-start, step-end, steps(n, jump)
: Define a step function with a specified number of steps and jump behavior.
Example values: linear, ease, ease-in, ease-out, ease-in-out, cubic-bezier(n,n,n,n), step-start, step-end, steps(n, jump)
“transition-timing-function - CSS: Cascading Style Sheets | MDN” (developer.mozilla.org). Retrieved April 26, 2023.
What does the transition-delay
CSS property do?
The transition-delay
CSS property specifies the time to wait before starting a CSS transition when the specified property changes.
“transition-delay - CSS: Cascading Style Sheets | MDN” (developer.mozilla.org). Retrieved April 26, 2023.
What is the syntax of the transition-delay
CSS property?
transition-delay: time-1, time-2, ...;
Values
- The time values can be given in seconds (e.g.,
1s
) or milliseconds (e.g.,1000ms
).
Example values: 0s, 200ms
“transition-delay - CSS: Cascading Style Sheets | MDN” (developer.mozilla.org). Retrieved April 26, 2023.
What does the transition
CSS shorthand property do?
The transition
CSS property is a shorthand for setting the transition-property
, transition-duration
, transition-timing-function
, and transition-delay
properties in a single declaration.
“transition - CSS: Cascading Style Sheets | MDN” (developer.mozilla.org). Retrieved April 26, 2023.
What is the syntax of the transition
CSS shorthand property?
transition: property duration timing-function delay;
Values
- Order of values is important: property (required), duration (required), timing-function (optional, default is ease), delay (optional, default is 0s).
- Multiple transitions can be specified, separated by commas:
transition: width 0.5s ease-out 100ms, height 0.3s linear;
Example:
transition: width 0.5s ease-out 100ms;
“transition - CSS: Cascading Style Sheets | MDN” (developer.mozilla.org). Retrieved April 26, 2023.
How can you apply CSS transitions using pseudo-classes?
To apply CSS transitions when an element is in a specific state, use the :hover
, :focus
, :active
, or :checked
pseudo-classes. Add the transition properties to the base state of the element and define the property changes within the pseudo-class rule.
Example of using CSS transitions with the :hover pseudo-class
button { background-color: blue; transition: background-color 0.3s ease-in-out; } button:hover { background-color: red; }
How can you set different durations and delays for multiple properties?
Specify separate durations and delays for each property by listing them in the same order as the properties in the transition-property
rule. Use commas to separate values for different properties.
Example of setting different durations and delays for multiple properties
.box { transition-property: width, height, background-color; transition-duration: 0.5s, 1s, 0.3s; transition-delay: 0s, 100ms, 200ms; }
In this example, the width
transition has a 0.5s
duration and no delay, the height transition has a 1s
duration and a 100ms
delay, and the background-color
transition has a 0.3s
duration and a 200ms
delay.
Create a CSS rule that applies a transition to the background-color
property, with a duration of 0.8 seconds, an ease-in-out
timing function, and a delay of 300 milliseconds.
{ transition-property: background-color; transition-duration: 0.8s; transition-timing-function: ease-in-out; transition-delay: 300ms; }