原生checkbox(复选框)样式调整

根据UI需求,本文介绍了如何在HTML5中利用伪元素技巧来改变原生复选框的样式,以避免layui样式影响已绑定的点击事件。并提供了使用layui图标和阿里图标库的方法,以及修改content属性的步骤。

原生checkbox(复选框)样式调整

应UI要求改变原生复选框的样式,layui带出来样式会影响复选框已经绑定的点击事件。只能用伪元素来尝试解决这个问题。

在这里插入图片描述

代码:

input[type=checkbox] {
        text-align: center;
        vertical-align: middle;
        border: none;
        appearance: none;/*关键代码*/
        -webkit-appearance: none;
        outline: none;
        cursor: pointer;
    }
    input[type=checkbox]::after {
        content: " ";
        display: inline-block;
        width: 14px;
        height: 14px;
        border: solid 1px #1182e0;
        color: #fff;
        border-radius: 2px;
    }
    input[type=checkbox]:checked:after {
        content: "\e605";
        width: 14px;
        height: 14px;
        line-height: 13px;
        border: solid 1px #1182e0;
        color: #fff;
        background: #1182e0;
        font-family: layui-icon!important;
        font-size: 12px;
        font-style: normal;
        font-weight: 700;
        -webkit-font-smoothing: antialiased;
        border-radius: 2px;
    }

提示:1、用的是layui的小图标,也可以换成阿里的图标库icon,复制iconfont.css里定义font-family的几行样式代码替换
2、“\e605”:在网页f12选中对号图标的before或after查看其content取类似“\e605”替换,操作如图在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

前端一名小学生

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

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

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

打赏作者

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

抵扣说明:

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

余额充值