radio改版样式

10 篇文章 0 订阅
.sex_male ,.sex_female{ opacity: 0; cursor: pointer; -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)"; filter: alpha(opacity=0);}label{    display:-moz-inline-block;    display:inline-block;    margin:5px 0; padding-left:20px; line-height:18px; background: url("../images/radio-no.png") no-repeat;width: 18px;height: 18px;}label.checked{background: url("../images/radio-hover.png") no-repeat;width: 18px;height: 18px;}

$(function(){
    //单选事件
     labels = document.getElementById('male').getElementsByTagName('label');
     radios = document.getElementById('male').getElementsByTagName('input');
     for(i=0,j=labels.length ; i<j ; i++)
     {
         labels[i].onclick=function()
         {
             if(this.className == '') {
                 for(k=0,l=labels.length ; k<l ; k++)
                 {
                     labels[k].className='';
                     radios[k].checked = false;
                 }
                 this.className='checked';
                 try{
                     document.getElementById(this.name).checked = true;
                 } catch (e) {}
             }
         }
     }
});

<td id="male">
<input type="radio" class="sex_male" checked="checked" name="sex" value="" /><label name="sex_male" class="checked" for="sex_male"></label>
<input type="radio" class="sex_female" name="sex" value="" /><label name="sex_female" for="sex_female"></label>
</td>




Radio button 是一种用于表单的单选按钮,通常会和一些样式一起使用以增加可视化效果和用户体验。下面是一些常见的 radio button 样式示例: 1. 原生样式: ```html <label> <input type="radio" name="gender" value="male"> Male </label> <label> <input type="radio" name="gender" value="female"> Female </label> ``` 2. 自定义样式: ```html <label class="radio-container">Male <input type="radio" name="gender"> <span class="radio-checkmark"></span> </label> <label class="radio-container">Female <input type="radio" name="gender"> <span class="radio-checkmark"></span> </label> ``` ```css /* 自定义样式 */ .radio-container { display: block; position: relative; padding-left: 35px; margin-bottom: 12px; cursor: pointer; font-size: 16px; user-select: none; } .radio-container input { position: absolute; opacity: 0; cursor: pointer; } .radio-checkmark { position: absolute; top: 0; left: 0; height: 20px; width: 20px; background-color: #eee; border-radius: 50%; } .radio-container:hover input ~ .radio-checkmark { background-color: #ccc; } .radio-container input:checked ~ .radio-checkmark { background-color: #2196F3; } .radio-checkmark:after { content: ""; position: absolute; display: none; } .radio-container input:checked ~ .radio-checkmark:after { display: block; } .radio-container .radio-checkmark:after { top: 50%; left: 50%; transform: translate(-50%, -50%) scale(0.7); width: 10px; height: 10px; border-radius: 50%; background: white; } ``` 3. 使用 CSS 框架: Bootstrap: ```html <div class="form-check"> <input class="form-check-input" type="radio" name="gender" id="male" value="male"> <label class="form-check-label" for="male"> Male </label> </div> <div class="form-check"> <input class="form-check-input" type="radio" name="gender" id="female" value="female"> <label class="form-check-label" for="female"> Female </label> </div> ``` ```css /* Bootstrap 样式 */ .form-check-input:checked ~ .form-check-label::before { color: #fff; border-color: #2196f3; background-color: #2196f3; } .form-check-input:focus ~ .form-check-label::before { box-shadow: 0 0 0 1px #2196f3, 0 0 0 0.2rem rgba(33, 150, 243, 0.25); } .form-check-label::before { position: absolute; top: 0.25rem; left: -1.5rem; display: block; width: 1rem; height: 1rem; pointer-events: none; content: ""; background-color: #fff; border: #adb5bd solid 1px; } .form-check-input { position: absolute; margin-top: 0.3rem; margin-left: -1.6rem; margin-right: 0.25rem; } ``` 以上是一些 radio button 样式的示例,你可以根据需要选择适合自己的样式
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值