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
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值