css3 transition translate

新增动画

transform translate   变换-平移
transition      过渡         
transform-origin  变换原点
rotate 旋转

scale  大小

keyframes  关键帧

translate   翻译为平移 默认是以自身的宽高平移 典型案例是 将元素设置水平垂直的居中对齐

 

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    div{
      position: absolute;
      top: 50%;
      left: 50%;
      width: 200px;
      height: 200px;
      /* line-height: 200px; */
      text-align: center;
      background-color: pink;
      /* 变换平移 */
      transform: translate(-50%,-50%);
    }
    p{
      position: absolute;
      top: 50%;
      left: 50%;
      /* 变化平移 */
      transform: translate(-50%,-50%);
    }
  </style>
</head>
<body>
  <div>    
    <p>transform: translate(50%,50%); 水平垂直居中对齐</p>
  </div>
</body>
</html>

 

结果

 transition    翻译为过度  scale   翻译为大小

 

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .test {
        position: absolute;
        top: 50%;
        left: 50%;
        width: 100px;
        height: 100px;
        /* 居中 */
        transform: translate(-50%,-50%);
      }
      .big {
        width: 100px;
        height: 100px;
        background-color: pink;
        /* 过渡 */
        transition: all 2s;
      }
      .big:hover {
        /* 缩放 */
        transform: scale(2);
      }
      .lette {
        width: 100px;
        height: 100px;
        background-color: red;
        transition: all 2s;
      }
      .lette:hover {
        /* 缩放 */
        transform: scale(0.5);
      }
    </style>
  </head>
  <body>
    <div class="test">
      <div class="big">放大2倍</div>
      <div class="lette">缩小1倍</div>
    </div>
  </body>
</html>

  

  

 

 

 

 

posted on 2023-10-30 11:55  是水饺不是水饺  阅读(71)  评论(0)    收藏  举报

导航