css平面转换

一.平移

1.transform: translate(水平移动距离, 垂直移动距离)

单独设置某个方向的移动距离:translateX() & translateY()

translate()如果只给出一个值, 表示x轴方向移动距离

2.取值

像素单位数值

百分比(参照物为盒子自身尺寸)

3.实例

<!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>
        .box{
            border: 2px solid black;
            width: 400px;
            height: 300px;
            margin: 0 auto;
        }
        .heart{
            transition: all 0.5s;
            width: 100px;
            height: 80px;
            background-color: aqua;
            
        }
        .box:hover .heart{
            /* transform: translate(100px,100px); */
            /* 百分比:盒子自身的百分比 */
            /* transform: translate(-50%,-50%); */
            /* 只给出一个值表示x轴移动距离或者translateX() */
            /* transform: translate(300px); */
            /* translateY()表示沿着y轴移动的距离 */
            transform: translateY(100px);
        }
    </style>
</head>
<body>
    <div class="box">
    <div class="heart"></div>
    </div>
</body>
</html>

二、旋转

1.transform: rotate(角度)

单位:deg

取值:

取值为正, 则顺时针旋转

取值为负, 则逆时针旋转

实例:

<!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>
        img{
            width: 123px;
            height: 123px;
            transition: all 2s;
           
        }
        img:hover{
           
            transform: rotate(-360deg);
            
        }
    </style>
</head>
<body>
    <img src="rotate.png" alt="">
</body>
</html>

2.transform-origin: (原点水平位置 原点垂直位置)改变转换原点

取值:方位名词(left、top、right、bottom、center)

实例:

<!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>
        img{
            width: 300px;
            height: 300px;
            transition: all 2s;
            transform-origin: right bottom;
        }
        img:hover{
         
            transform: rotate(-360deg);
        }
    </style>
</head>
<body>
    <img src="rotate.png" alt="">
</body>
</html>

三、transform复合属性

  transform:translate() rotate() ;

实例:

<!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>
        .box{
            width: 800px;
            height: 200px;
            border: 1px solid black;
            margin:  0 auto;
        }
        img{
           width: 200px;
           transition: all 8s;
        }
        .box:hover img{
            /* 向右平移600px,旋转360度 */
            transform:translate(600px) rotate(360deg) ;
        }
    </style>
</head>
<body>
 <div class="box">
<img src="tyre.png" alt="">
 </div>   
</body>
</html>

四、放缩

transform: scale(x轴缩放倍数, y轴缩放倍数);

取值:

一般情况下, 只为scale设置一个值, 表示x轴和y轴等比例缩放

 transform: scale(缩放倍数);

scale值大于1表示放大, scale值小于1表示缩小

实例:

<!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>
        .box{
            width: 400px;
            height: 400px;
            background-color: aqua;
        }
        .box img{
            width: 100%;
            transition: all 0.5s;
        }
        .box:hover img{
            transform: scale(1.6);
        }
    </style>
</head>
<body>
  <div class="box">
<img src="product.jpeg" alt="">
  </div>  
</body>
</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Gxbfeng

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

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

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

打赏作者

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

抵扣说明:

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

余额充值