自定义单选框样式

大多数情况下我们需要重新定义单选框的样式,比如下图:


html代码如下:

<div class="user-info-detail">
    <p>
        <span class="item-name">性别</span>
        <label class="choice-item radio-sex" for="radio1">
            <input id="radio1" name="sex" type="radio" value="MAN"/><span></span>男
        </label>
        <label class="radio-sex" for="radio2">
            <input id="radio2" name="sex" type="radio" value="MALE"/><span></span>女
        </label>
    </p>
<div>

css代码如下:

.user-info-detail{
        margin: 0 30px;
        p{
          position: relative;
          height: 40px;
          line-height: 40px;
          margin-bottom: 18px;
          font-size: 14px;
          .item-name{
            display: inline-block;
            width: 72px;
            margin-right: 18px;
            color: #999;
            text-align: right; 
          }   
          label{
            position: relative;
            padding:0 10px 0 25px;
            span{
              position: absolute;
              left: 0;
              top: 0;
              bottom: 0;
              width: 16px;
              height: 16px;
              margin: auto;
              border: 1px solid #ccc;
              border-radius: 100%;
              &:after{
                content: '';
                position: absolute;
                top: 0;
                bottom: 0;
                left: 0;
                right: 0;
                width: 6px;
                height: 6px;
                margin: auto;
                border-radius: 100%;
                background: #fff;
                //-webkit-transform: scale(0);
                //transform: scale(0);
                //-webkit-transition: all .3s;
                //transition: all .3s;
              }
            }
          }
          .choice-item{
            margin-right: 25px;
          }
          input[type="radio"]{
            display: none;
          }
          input[type="radio"]:checked + span{
            border-color: #34dacc;
            background: #34dacc;
          }
        }
      }

如果给该单选框赋初始值,可以这样:

$(".radio-sex input[value="+ data.sex +"]").attr("checked",true);

版权声明:本文为博主原创文章,未经博主允许不得转载。https://blog.csdn.net/qq_36584352/article/details/80225158

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值