01-按钮左右到中间运动

01-按钮左右到中间运动

效果图

晚上回去加

代码实现

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>01-鼠标悬浮上去有一个左右移动的动画</title>
    <style>
        :root {
            --btn-bg-color: #66b1ff;
            --hover_bg_color: #e11010;
            --btn-width: 200px;
            --btn-height: 30px;
        }

        .container {
            width: 100%;
            /*background-color: #000;*/
            height: 30px;
            display: flex;
            /*flex-direction: column;*/
            place-content: center;
            /*margin: 0 auto;*/
        }

        .container > button {
            outline: none;
            border: 2px solid var(--btn-bg-color);
            border-radius: 4px;
            width: var(--btn-width);
            height: var(--btn-height);
            background-color: var(--btn-bg-color);;
            cursor: pointer;
            position: relative;
            overflow: hidden;
        }

        .container > button::after {
            content: "";
            position: absolute;
            top: 50%;
            left: 50%;
            z-index: 0;
            background: var(--hover_bg_color);
            width: var(--btn-width);
            height: 0;
            /*height: var(--btn-width);*/
            transform: translateX(-50%) translateY(-50%) rotate(90deg);
            transition: all, 0.75s ease 0s;
        }

        .container > button:hover::after {
            height: var(--btn-width);
        }
    </style>
</head>
<body>
<div class="container">
    <button value="提交">提交</button>
</div>
</body>
</html>

大致逻辑

  1. 使用伪类创建一个元素,然后把这个元素放在按钮的上50%的位置,左50%的位置。

image-20221223160006250

  1. 在使用transform将伪元素覆盖到之前的元素,

image-20221223160040499

再将伪元素的高设置按钮的宽。注意,注意,注意,这是伪元素的高要设置为按钮的宽

image-20221223160100995

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值