纯CSS单选实现

本文介绍了一种使用纯CSS实现自定义样式的Radio按钮的方法。通过巧妙地利用伪元素及CSS3特性,如过渡效果、阴影及背景渐变等,实现了外观美观且交互友好的Radio选择器。该方案无需额外JavaScript支持,适用于需要高度定制化的UI设计场景。

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

  .radio{
            display: inline-block;
            position: relative;
            line-height: 18px;
            margin-right: 10px;
            cursor: pointer;
        }
        .radio input{
            display: none;
        }
        .radio .radio-bg{
            display: inline-block;
            height: 18px;
            width: 18px;
            margin-right: 5px;
            padding: 0;
            background-color: #45bcb8;
            border-radius: 100%;
            vertical-align: top;
            box-shadow: 0 1px 15px rgba(0, 0, 0, 0.1) inset, 0 1px 4px rgba(0, 0, 0, 0.1) inset, 1px -1px 2px rgba(0, 0, 0, 0.1);
            cursor: pointer;
            transition: all 0.2s ease;
        }
        .radio .radio-on{
            display: none;
        }
        .radio input:checked + span.radio-on{
            width: 10px;
            height: 10px;
            position: absolute;
            border-radius: 100%;
            background: #FFFFFF;
            top: 4px;
            left: 4px;
            box-shadow: 0 2px 5px 1px rgba(0, 0, 0, 0.3), 0 0 1px rgba(255, 255, 255, 0.4) inset;
            background-image: linear-gradient(#ffffff 0, #e7e7e7 100%);
            transform: scale(0, 0);
            transition: all 0.2s ease;
            transform: scale(1, 1);
            display: inline-block;
        }

             <td class="radio"><input value = "" name="radio" type="radio" checked><label for="radio-1" class="radio-label"></label></td> 
             <td class="radio"><input value = "" name="radio" type="radio"><label  for="radio-2" class="radio-label"></label></td>
             <td class="radio"><input value = "" name="radio" type="radio"><label  for="radio-3" class="radio-label"></label></td>
             <td class="radio"><input value = "" name="radio" type="radio"><label  for="radio-4" class="radio-label"></label></td>
             <td class="radio"><input value = "" name="radio" type="radio"><label  for="radio-5" class="radio-label"></label></td>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值