css修改浏览器原生的单选框和复选框

  • 效果图
    效果图

  • css 代码

    .box1 input[type="checkbox"]+label::before {
      content: '\a0'; /*不换行空格*/
        display: inline-block;
        width: 0.8em;
        height: 0.8em;
        margin-right: 0.2em;
        border-radius: 0.2em;
        background: silver;
        text-indent: 0.15em;
        line-height: 0.65;
        vertical-align: 0.2em;
        margin-top: 0.2em;
    }
    
    
    .box1 input[type="checkbox"]:checked+label::before {
        content: '\2713'; /*复选框中的对号*/
        background: yellowgreen;
        color: #fff;
    }
    
    .box1 input[type="checkbox"] {
        position: absolute;
        clip: rect(0, 0, 0, 0);
    }
    
    /*****************************************************************/
    .box2 input[type="checkbox"] {
        position: relative;
        line-height: 1;
    }
    
    .box2 input[type="checkbox"]::before {
        content: '\a0';
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        display: block;
        border-radius: 2px;
    }
    
    .box2 input[type="checkbox"]:checked::before {
        content: '\2713';/*复选框中的对号*/
        background: yellowgreen;
        color: #fff;
    }
    
    
    
    /*****************************************************************/
    input[type="radio"] {
        position: relative;
    }
    
    input[type="radio"]::before {
        content: '\a0';
        display: block;
        position: absolute;
        inset: 0;
        border-radius: 50%;
        border: 1px solid yellowgreen;
        background-color: #fff;/* 盖住原生的单选框*/
    }
    
    input[type="radio"]:checked:after {
        content: '\a0';
        background-color: yellowgreen;
        position: absolute;
        inset: 0;
        border-radius: 50%;
        transform: scale(0.59);
    }
    
  • html代码

    <div class="box1">
        <input type="checkbox" id="awesome">
        <label for="awesome">Awesome!</label>
    </div>
    
    <div class="box2">
        <label for="awesome2">
            <input type="checkbox" id="awesome2">
            Awesome!
        </label>
    </div>
    
    <div class="box3">
        <label>
            <input type="radio" name="anm1">
            Awesome!
        </label>
        <label>
            <input type="radio" name="anm1">
            Awesome2!
        </label>
    </div>
    
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值