css3 transtion属性的使用

主要实现多个内容排列时从下到上过渡 或者 从左到右过渡。
思路:主要是利用flex布局的flex-direction属性和align-items属性。

flex-direction属性决定主轴的方向(即项目的排列方向)
align-items属性定义项目在交叉轴上如何对齐。

一、从下到上过渡(方案1) 
1.先上效果图

效果图

2.代码如下(示例):

html

 <div class="box">
   <div class="box1">111</div>
   <div class="box2">222</div>
   <div class="box3">333</div>
   <div class="box4">444</div>
 </div>

css


  .box{
    background-color: pink;
    width: 400px;
    height: 400px;
    display: flex;
    flex-direction: column-reverse;
  }
  .box1{
    width: 400px;
    height: 50px;
    background-color:#142385;
    transition: height 1s;
  }
  .box2{
    width: 400px;
    height: 50px;
    background-color: #159298;
    transition: height 1s;
  }
  .box3{
    width: 400px;
    height: 50px;
    background-color: #42bcad;
    transition: height 1s;
  }
  .box4{
    width: 400px;
    height: 50px;
    background-color: #66ffcc;
    transition:height 1s;
  }
  .box1:hover,
  .box2:hover,
  .box3:hover,
  .box4:hover{
    height: 300px;
  }
二、从下到上过渡(方案2)
1.先上效果图

flex-end

2.代码如下(示例):

html

 <div class="box">
   <div class="box1">111</div>
   <div class="box2">222</div>
   <div class="box3">333</div>
   <div class="box4">444</div>
 </div>

css


  .box{
    background-color: pink;
    width: 400px;
    height: 400px;
    display: flex;
    align-items: flex-end;
  }
  .box1{
    width: 400px;
    height: 50px;
    background-color:#142385;
    transition: height 1s;
  }
  .box2{
    width: 400px;
    height: 50px;
    background-color: #159298;
    transition: height 1s;
  }
  .box3{
    width: 400px;
    height: 50px;
    background-color: #42bcad;
    transition: height 1s;
  }
  .box4{
    width: 400px;
    height: 50px;
    background-color: #66ffcc;
    transition:height 1s;
  }
  .box1:hover,
  .box2:hover,
  .box3:hover,
  .box4:hover{
    height: 300px;
  }
三、从右向左过渡(方案1)
1.先上效果图

row-

2.代码如下(示例):

html

 <div class="box">
   <div class="box1">111</div>
   <div class="box2">222</div>
   <div class="box3">333</div>
   <div class="box4">444</div>
 </div>

css

 .box {
    background-color: pink;
    width: 400px;
    height: 400px;
    display: flex;
    flex-direction: row-reverse;
  }
  .box1 {
    width: 50px;
    height: 400px;
    background-color: #142385;
    transition: width 1s;
  }
  .box2 {
    width: 50px;
    height: 400px;
    background-color: #159298;
    transition: width 1s;
  }
  .box3 {
    width: 50px;
    height: 400px;
    background-color: #42bcad;
    transition: width 1s;
  }
  .box4 {
    width: 50px;
    height: 400px;
    background-color: #66ffcc;
    transition: width 1s;
  }
  .box1:hover,
  .box2:hover,
  .box3:hover,
  .box4:hover {
    width: 300px;
  }
四、从右向左过渡(方案2)
1.先上效果图

column

2.代码如下(示例):

html

 <div class="box">
   <div class="box1">111</div>
   <div class="box2">222</div>
   <div class="box3">333</div>
   <div class="box4">444</div>
 </div>

css

  .box {
    background-color: pink;
    width: 400px;
    height: 400px;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
  }
  .box1 {
    width:100px;
    height: 100px;
    background-color: #142385;
    transition: width 1s;
  }
  .box2 {
    width: 100px;
    height: 100px;
    background-color: #159298;
    transition: width 1s;
  }
  .box3 {
    width: 100px;
    height: 100px;
    background-color: #42bcad;
    transition: width 1s;
  }
  .box4 {
    width: 100px;
    height: 100px;
    background-color: #66ffcc;
    transition: width 1s;
  }
  .box1:hover,
  .box2:hover,
  .box3:hover,
  .box4:hover {
    width: 400px;
  }

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,我会为您解答关于html中transition属性CSS3Transition动画属性的用法。 在HTML中,transition属性表示元素在一定时间内从一种样式转换为另一种样式的过程。transition属性需要指定以下几个参数: - transition-property:指定过渡的CSS属性,可以使用all来表示所有属性都过渡。 - transition-duration:指定过渡的时间,以秒或毫秒为单位。 - transition-timing-function:指定过渡的时间函数,可以使用一些预定义的函数,如linear、ease、ease-in、ease-out等。 - transition-delay:指定过渡的延迟时间,以秒或毫秒为单位。 举个例子,如果您想让一个元素在鼠标悬停时变成红色,可以这样写: ``` div { background-color: blue; transition-property: background-color; transition-duration: 1s; transition-timing-function: ease-in-out; } div:hover { background-color: red; } ``` 这样,在鼠标悬停时,该元素的背景色会从蓝色平滑地过渡到红色。 在CSS3中,Transition动画属性是与transition属性相关的一组属性,包括以下几个参数: - transition-property:同HTML中的transition-property参数。 - transition-duration:同HTML中的transition-duration参数。 - transition-timing-function:同HTML中的transition-timing-function参数。 - transition-delay:同HTML中的transition-delay参数。 - transition: 简写形式,可以一次性指定以上所有参数。例如:transition: background-color 1s ease-in-out 0s。 此外,CSS3中还新增了一些过渡效果,包括旋转、缩放、平移等。举个例子,如果您想让一个元素在鼠标悬停时旋转180度并缩小一半,可以这样写: ``` div { width: 100px; height: 100px; background-color: blue; transition: transform 1s ease-in-out; } div:hover { transform: rotate(180deg) scale(0.5); } ``` 这样,在鼠标悬停时,该元素会以一个180度的旋转和50%的缩放平滑地过渡到新的状态。 希望这些内容能够帮到您,如果您还有其他问题,请随时提出。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值