input 纯CSS 自定义 单选框/多选框 样式

本文分享了一段HTML和CSS代码,用于创建自定义样式的单选按钮。通过使用绝对定位和伪元素,实现了按钮的美观展示,并展示了如何通过:checked伪类改变选中状态的样式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

备忘,直接上代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>样式</title>
    <style>
        #d1{
            width:200px;
            margin: 100px auto;
        }
        label{
            position: relative;
            display: inline-block;
            width: 48%;
        }
        .inputStatus{
            position: absolute;
            top:0;
            left: 0;
            width: 22px;
            height: 15px;
            opacity: 0;
        }

        .inputStyle2{
            position: relative;
            top: 3px;
            left: 0;
            display: inline-block;
            padding: 10px;
            /*多选*/
            background: url("img/allBgs.png") no-repeat -3px -2px;
            /*单选*/
            /*background: url("img/allBgs.png") no-repeat -52px -2px;*/
        }

        .inputStatus:checked+.inputStyle2{
            /*多选*/
            background: url("img/allBgs.png") no-repeat -28px -2px;
            /*单选*/
            /*background: url("img/allBgs.png") no-repeat -75px -2px;*/
        }

    </style>
</head>
<body>

<div  id="d1">
    <label class='' style="position: relative;">
        <input type='radio'  id="history_finish0" class='inputStatus' name="v1">
        <span class='inputStyle2'></span> 确定
    </label>

    <label class='labelRadio' style="margin-bottom: 0;">
        <input type='radio' class='inputStatus' name="v1">
        <span class='inputStyle2'></span> 取消
    </label>
</div>

</body>
</html>

效果图:
在这里插入图片描述


在这里插入图片描述


素材背景图:
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值