transform

transform: translate让盒子水平垂直居中

<style>
        div {
            position: relative;
            width: 500px;
            height: 500px;
            background-color: pink;
        }

        p {
            position: absolute;
            top: 50%;
            left: 50%;
            width: 200px;
            height: 200px;
            background-color: purple;
            /* 第一种做法 */
            /* margin-left: -100px;
            margin-top: -100px; */
            /* 第二种 */
            /* 盒子往上走高度的一半 */
            transform: translate(-50%, -50%);
        }
    </style>
</head>

<body>
    <div>
        <p></p>
    </div>
</body>

transform: rotate(360deg);旋转

<style>
        img {
            width: 150px;
            /* 45deg顺时针旋转45度 */
            /* transform: rotate(45deg); */
            border: 5px solid pink;
            border-radius: 50%;
            /* 过度写到本身上,谁做过度给谁加 */
            transition: all 2s;
        }
        img:hover {
            transform: rotate(360deg);
        }
    </style>
</head>

<body>
    <img src="media/pic.jpg" alt="">
</body>

三角制作

     div {
            position: relative;
            width: 249px;
            height: 35px;
            border: 1px solid #000;
        }

        div::after {
            position: absolute;
            content: "";
            top: 10px;
            right: 15px;
            width: 10px;
            height: 10px;
            border-right: 1px solid #000;
            border-bottom: 1px solid #000;
            transform: rotate(45deg);
            transition: all 0.2s;
        }

        /*鼠标经过盒子,里面的三角旋转*/
        div:hover::after {
            transform: rotate(225deg);
        }
    </style>
</head>

<body>
    <div></div>
</body>

</html>

转换中心点

 <style>
        div {
            width: 200px;
            height: 200px;
            background-color: pink;
            margin: 100px auto;
            transition: all 1s;
            /*1方位名词, 以左下角为中心点 */
            /* transform-origin: left bottom; */
            /*2 默认50% 50% */
            /* 3可以是px */
            transform-origin: 50px 50px;
        }

        div:hover {
            transform: rotate(360deg);
        }
    </style>
</head>

<body>
    <div></div>
</body>

transform: scale(x,y);图片缩放

<style>
        div {
            width: 200px;
            height: 200px;
            background-color: pink;
            margin: 100px auto;
            /* 这只变换中心点 */
            transform-origin: bottom left;

        }

        div:hover {
            /*里面的竖直不跟单位,宽高变为原来两倍*/
            /* transform: scale(2, 2); */
            transform: scale(2);
            /* 优势之处是变换不会影响其他的盒子 */
        }
    </style>
</head>

<body>
    <div></div>
</body>

</html>

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值