css伪元素实现关闭和选项按钮

原理很简单;

关闭按钮:通过盒子的伪元素(::before和::after)实现关闭那俩叉;

选项按钮:同上,不同的是要借用一个i标签;

直接写好demo拉走,很短,包含两个按钮样式

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <title>button</title>
</head>
<style>
    div {
        width: 50px;
        height: 50px;
        border-radius: 0 50% 50% 50%;
        background: #80bd01;
        margin: 10px auto;
        position: relative;
    }
    /*关闭按钮*/
    .close::before, .close::after {
        content: '';
        width: 4px;
        height: 30px;
        background: #000;
        position: absolute;
        top: 11px;
        left: 22px;
    }
    .close::before {
        transform: rotate(45deg);
    }
    .close::after {
        transform: rotate(-45deg);
    }
    /*选项按钮,自己实现时去掉hover就行*/
    .option::before ,.option::after, .option i {
        content: '';
        width: 28px;
        height: 4px;
        background: #000;
        position: absolute;
        top: 12px;
        left: 11px;
    }
    .option i {
        top: 22px;
    }
    .option::after {
        top: 32px;
    }
</style>
<body>
    <div class="close"></div>
    <div class="option">
        <i></i>
    </div>
</body>
</html>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值