Home > Web Front-end > CSS Tutorial > How to Correctly Use CSS Transition Shorthand for Multiple Properties?

How to Correctly Use CSS Transition Shorthand for Multiple Properties?

DDD
Release: 2024-11-27 20:06:15
Original
494 people have browsed it

How to Correctly Use CSS Transition Shorthand for Multiple Properties?

CSS Transition with Multiple Properties: Shorthand Syntax Clarification

The CSS transition shorthand syntax enables us to transition multiple properties simultaneously. However, the syntax provided in the given example is incorrect.

Shorthand Syntax Structure:

transition: <property> || <duration> || <timing-function> || <delay> [, ...];
Copy after login

Note: The duration must precede the delay if the delay is specified.

Correct Shorthand Syntax for the Given Example:

transition: height 0.5s, opacity 0.5s 0.5s;
Copy after login

This syntax indicates that:

  • The height property transitions over 0.5 seconds.
  • The opacity property transitions over 0.5 seconds, with a delay of 0.5 seconds.

Simplified Syntax:

If transitioning all properties concurrently, you can use the following simplified shorthand syntax:

transition: all 0.5s;
Copy after login

Code Example with Correct Syntax:

.element {
  transition: height 0.5s, opacity 0.5s 0.5s;
  height: 0;
  opacity: 0;
  overflow: 0;
}
.element.show {
  height: 200px;
  opacity: 1;
}
Copy after login

This updated code should now transition the element's height and opacity smoothly.

The above is the detailed content of How to Correctly Use CSS Transition Shorthand for Multiple Properties?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template