动画+过渡+弹性布局

本文介绍了HTML5中的动画、过渡和弹性布局。动画涉及到帧率和关键帧设置;过渡需要指定样式变化和过渡时间;弹性布局允许元素根据页面大小变化,包括display、flex-direction、justify-content等属性的使用,以及对子元素的对齐和伸缩比例的控制。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

动画

动画是从一种状态转变为另一个状态的过程.这就涉及到了另个名词帧率.我们把一个过程分为起始状态和结束状态,他们中间无数个小时间节点就是帧,每一帧有每一个状态。这些状态在一定的时间内连续执行就形成了动画。

创建动画的工程:

动画的名称:animation-name:动画的名称

动画的周期:animation:6s

动画的时间速度曲线:animation-timing-function:linear

动画的次数:animation-iteration-count:infinite(无限)

动画的暂停:animation-play-state:paused

动画的开始:

@key frames {

        from{ }(开始的状态)

        to{ }(结束的状态)

}

综合设置: animation: move 4s linear infinite;

代码如下:

<style>
        div {
            width: 200px;
            height: 200px;
            background-color: red;

            /* 2使用 */
            animation: move 4s linear infinite;
            /* animation-delay: 2s;
            animation-iteration-count: infinite; 
            animation-direction: alternate; 

            animation: myfirst 5s linear 2s infinite alternate;  */
            
        }

        div:hover{
            animation-play-state: paused;
        }

        /* 1,。定义动画 */
        @keyframes move {
            from {
                transform: translateX(0);
                background-color: red;
            }
            25%{
                transform: translate(1000px,0px);
                background-color: yellow;
            }

            50%{
                transform: translate(1000px,500px);
                background-color: green;
            }
            75%{
                transform: translate(0px,500px);
                background-color: blue;
            }

            to  {
                transform: translateX(0);
            }
        }
    </style>

过渡

过渡就元素从一种样式改变为另一种样式.

过渡属性:transition

必须满足的两个条件:

1.设置过渡的css样式

2.设置需要过渡的时间

过渡的属性:transition-property:background-color  height;

过渡的周期:transition-duration:2s

过渡的时间速度曲线:transition-timing-function:linear(默认为ease)

过渡的延迟:transition-delay:3s;

综合设置过渡: css属性  周期 速度曲线 延迟

transition:background-color  4s linear 1s,height 2s ease 0s;

如给盒子一个移入过渡,代码如下:

<style>
    .box {
      width: 500px;
      height: 200px;
      background-color: red;
      text-align: center;
      font-size: 40px;
      color: white;
      transition-property: background-color height;
      transition-duration: 2s;
      transition-timing-function: linear;
      transition-delay: 3s;
      transition: background-color 4s linear 1s,height 2s ease 0s,border-radius 3s,transform 5s;
    }
    .box:hover {
      background-color: blue;
      height: 600px;
      border-radius: 50%;
      transform: translateY(200px);
    }
  </style>

弹性布局:

flex(弹性盒,伸缩盒)弹性布局是css中又一种布局手段,它主要代替浮动来完成页面的布局。
flex可以使元素具有弹性,让元素可以跟着页面大小的改变而改变

弹性布局的使用:

弹性容器:要使用弹性盒,必须先将一个元素设置为弹性容器
我们通过display来设置弹性容器
display:flex 来设计为块级弹性容器
display:inline-flex 设计为行内的弹性容器(不会独占一行)

flex-direction:row(默认:主轴是从左到右)/row-reverse(主轴从右到左)/column(主轴从上到下)/column-reverse(主轴从下到上)     -------改变的方向

justify-content:flex-satart(默认):全部靠左依次排列

                       flex-end:全部靠右依次排列

                        center:使项目全部排列在中间部分.

                        space-between:沿主轴的项目之间的间距相等,第一个和最后一个项目离边距为零

                        space-around:沿主轴的项目之间的间距相等,第一个和最后一个项目离边距为中间间距的一半.

                        space-evenly:沿主轴的项目之间的间距相等,第一个和最后一个项目离边距与中间间距相等.

align-item:stretch(默认值):如果项目没有高度,会拉伸到容器的高度

                 flex-start:沿着交叉轴开始位置对齐.

                flex-end:沿着交叉轴结束位置对齐.

                center:沿着交叉轴居中位置对齐.

flex-wrap(设置超出内容是否换行):nowrap(默认)不换行

                wrap:换行;

                wrap-reverse

align-content(设置项目换行的对齐方式):stretct(默认的)

                     flex-start  flex-end  center  space-between space-sround  space-evenly

align-self(设置项目在行中交叉轴方向上的对齐):flex-end  flex-start center

设置弹性子元素缩小比例属性:flex-shrink

子元素所占剩余元素百分比:flex-grow:1

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

WeChat624

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值