Laravel  
laravel
文档
数据库
架构
入门
php技术
    
Laravelphp
laravel / php / java / vue / mysql / linux / python / javascript / html / css / c++ / c#

css animation属性

作者:昂首向前走,   发布日期:2025-08-19   浏览:82

/* 使用 CSS animation 属性创建一个简单的动画效果 */

/* 定义关键帧 */
@keyframes example {
  0%   { background-color: red; left: 0px; top: 0px; }
  25%  { background-color: yellow; left: 200px; top: 0px; }
  50%  { background-color: blue; left: 200px; top: 200px; }
  75%  { background-color: green; left: 0px; top: 200px; }
  100% { background-color: red; left: 0px; top: 0px; }
}

/* 应用动画到元素 */
div {
  width: 100px;
  height: 100px;
  position: relative;
  background-color: red;
  animation-name: example;
  animation-duration: 4s;
  animation-iteration-count: infinite;
}

解释说明:

  1. @keyframes:定义了一个名为 example 的关键帧动画。它描述了动画在不同时间点的状态。
  2. animation-name:指定了要应用的关键帧名称,这里是 example
  3. animation-duration:设置动画的持续时间为 4 秒。
  4. animation-iteration-count:设置动画循环次数为无限次(infinite)。

通过这些属性,我们可以创建一个从红色变为黄色、蓝色、绿色,再回到红色的方块,并且它会在页面上移动。

上一篇:css id选择器

下一篇:css背景颜色渐变

大家都在看

css好看的字体

css 红色

css 瀑布流布局grid

css文字超长省略号

css 渐变字体

css背景图片等比例缩放

css文字删除线

animation css3

css 自定义滚动条

css flex gap

Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3

Laravel 中文站