【css】鼠标移入出现不同线性框效果

<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>
        h3 {
            text-align: center;
            margin: 100px auto 40px;
        }
        .items {
            display: flex;
            align-self: center;
            max-width: 60%;
            margin:0 auto;
        }
        .item{
            position: relative;
            width: 23.5%;
            height: 200px;
            background-color: #ccc;
            margin-right: 2%;
        }
        .item::before {
            content: '';
            position: absolute;
            left: 0;
            top: 0;
            background: red;
            content: "";
            width: 100%;
            height: 2px;
            box-sizing: border-box;
            transition: 0.4s;
            transform-origin: left top;
            z-index: 2;
            transform: scaleX(0);
        }
        .item::after {
            position: absolute;
            right: 0;
            top: 0;
            background: red;
            content: "";
            width: 2px;
            height: 100%;
            box-sizing: border-box;
            transition: 0.4s;
            transform-origin: left top;
            transform: scaleY(0);
        }
        .item i::before{
            position: absolute;
            right: 0;
            bottom: 0;
            background: red;
            content: "";
            width: 100%;
            height: 2px;
            box-sizing: border-box;
            transition: 0.4s;
            transform-origin: right top;
            transform: scaleX(0);
        }
        
        .item i::after{
            position: absolute;
            left: 0;
            bottom: 0;
            background: red;
            content: "";
            width: 2px;
            height: 100%;
            box-sizing: border-box;
            transition: 0.4s;
            transform-origin: left bottom;
            transform: scaleY(0);
        }

        /* 效果一 */
      
        .box1 .item:hover::before{
            transform: scaleX(1);
        }
        
        .box1 .item:hover::after{
            transform: scaleY(1);
            transition-delay: 0.4s;
        }
        .box1 .item:hover i:before {
            transform: scaleX(1);
            transition-delay: 0.8s;
        }
        .box1 .item:hover i::after {
            transform: scaleY(1);
            transition-delay: 1.2s;
        }


        /* 效果二 */

        .box2 .item:hover::before {
            transform: scaleX(1);
        }
        .box2 .item:hover::after{
            transform: scaleY(1);
            transition-delay: 0.4s;
        }
        .box2 .item:hover i:before {
            transform: scaleX(1);
        }
        .box2 .item:hover i::after {
            transform: scaleY(1);
            transition-delay: 0.4s;
        }

        /* 效果三 */
        .box3 .item::after{
            transform-origin: left bottom;
        }
        .box3 .item i::after{
            transform-origin: right top;
        }
        .box3 .item:hover::before {
            transform: scaleX(1);
        }
        .box3 .item:hover::after{
            transform: scaleY(1);
            transition-delay: 0.2s;
        }
        .box3 .item:hover i:before {
            transform: scaleX(1);
        }
        .box3 .item:hover i::after {
            transform: scaleY(1);
            transition-delay: 0.2s;
        }

        /* 效果四 */
        .box4 .item::after{
            transform-origin: left bottom;
        }
        .box4 .item i::after{
            transform-origin: right top;
        }
        .box4 .item:hover::before {
            transform: scaleX(1);
        }
        .box4 .item:hover::after{
            transform: scaleY(1);
        }
        .box4 .item:hover i:before {
            transform: scaleX(1);
        }
        .box4 .item:hover i::after {
            transform: scaleY(1);
        }
    </style>
</head>
<body>

    <!-- 效果一 -->
    <h3>效果一</h3>
    <div class="items box1">
        <div class="item"><i></i>1</div>
        <div class="item"><i></i>2</div>
        <div class="item"><i></i>3</div>
        <div class="item"><i></i>4</div>
    </div>

    
    <!-- 效果二 -->
    <h3>效果二</h3>
    <div class="items box2">
        <div class="item"><i></i>1</div>
        <div class="item"><i></i>2</div>
        <div class="item"><i></i>3</div>
        <div class="item"><i></i>4</div>
    </div>

     <!-- 效果三 -->
     <h3>效果三</h3>
     <div class="items box3">
         <div class="item"><i></i>1</div>
         <div class="item"><i></i>2</div>
         <div class="item"><i></i>3</div>
         <div class="item"><i></i>4</div>
     </div>

     <!-- 效果四 -->
     <h3>效果四</h3>
     <div class="items box4">
         <div class="item"><i></i>1</div>
         <div class="item"><i></i>2</div>
         <div class="item"><i></i>3</div>
         <div class="item"><i></i>4</div>
     </div>
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值