Home > Web Front-end > CSS Tutorial > Can CSS Grid Layout Properties Be Animated?

Can CSS Grid Layout Properties Be Animated?

Patricia Arquette
Release: 2024-11-28 14:42:11
Original
477 people have browsed it

Can CSS Grid Layout Properties Be Animated?

Animating CSS Grid Layout Properties

Despite the CSS Grid Layout specification indicating that transitions should apply to grid-template-columns and grid-template-rows, it does not currently work in most browsers.

Current Implementation:

Firefox supports animating grid properties, and provides an example here:
https://codepen.io/matuzo/post/animating-css-grid-layout-properties

Caveat:

The grid structure cannot change while animating the row and column dimensions. For instance, adding or removing rows would break the animation.

Test Code:

Consider the following test:

grid-container {
  display: inline-grid;
  grid-template-columns: 100px 20vw 200px;
  grid-template-rows: repeat(2, 100px);
  background-color: black;
  height: 230px;
  transition: 2s;
}

grid-container:hover {
  grid-template-columns: 50px 10vw 100px;
  grid-template-rows: repeat(2, 50px);
  background-color: red;
  height: 130px;
  transition: 2s;
}

grid-item {
  background-color: lightgreen;
}
Copy after login
<grid-container>
  <grid-item></grid-item>
  <grid-item></grid-item>
  <grid-item></grid-item>
  <grid-item></grid-item>
  <!-- Additional items -->
</grid-container>
Copy after login

Note: The test code in this example is enclosed in HTML comments for proper display.

The above is the detailed content of Can CSS Grid Layout Properties Be Animated?. 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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template