bootstrap拓展:radio按钮,纯css

本文介绍了一种使用HTML和CSS自定义样式的Radio按钮的方法,包括如何设置按钮的位置、大小和透明度等属性,并展示了如何在不同的状态(如选中状态)下改变按钮的外观。

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

HTML结构:

 

 

<div style="width:500px;height:100px;boorder:1px solid #ccc;text-align:center;margin:10px  auto;">
    <div class="radio-custom radio-primary" style="float:left;">
        <input type="radio" name="status" checked="checked" value="1">
        <label style="width:70px;">启用</label>
    </div>
    <div class="radio-custom radio-primary" style="float:left;">
        <input type="radio" name="status" value="0">
        <label>禁用</label>
    </div>
</div>

css样式:

 

.radio-custom input[type=radio] {
    position: absolute;
    margin-left: 0px;
    margin-top: 0;
    margin-bottom: 0;
}
.radio-custom input[type=radio] {
    width: 20px;
    height: 20px;
    opacity: 0;
    z-index: 1;
}
.radio-custom label {
    min-height: 22px;
    line-height:22px;
    margin-bottom: 0;
    font-weight: 300;
    cursor: pointer;
}
.radio-custom label {
    display: inline-block;
    vertical-align: middle;
    position: relative;
    padding-left: 30px;
}
.radio-custom label::before {
    content: "";
    display: inline-block;
    position: absolute;
    width: 20px;
    height: 20px;
    left: 0;
    margin-left: 0px;
    border: 1px solid #e4eaec;
    border-radius: 50%;
    background-color: #fff;
    -webkit-transition: border .3s ease-in-out 0s,color .3s ease-in-out 0s;
    -o-transition: border .3s ease-in-out 0s,color .3s ease-in-out 0s;
    transition: border .3s ease-in-out 0s,color .3s ease-in-out 0s;
}
.radio-custom input[type=radio]:checked+label::before {
    border-color: #e4eaec;
    border-width: 10px;
}
.radio-primary input[type=radio]:checked+label::before {
    border-color: #62a8ea;
}
.radio-custom label::after {
    display: inline-block;
    position: absolute;
    content: " ";
    width: 6px;
    height: 6px;
    left: 7px;
    top: 7px;
    margin-left: 0px;
    border: 2px solid #76838f;
    border-radius: 50%;
    background-color: transparent;
    -webkit-transform: scale(0,0);
    -ms-transform: scale(0,0);
    -o-transform: scale(0,0);
    transform: scale(0,0);
    transition-transform: .1s cubic-bezier(.8,-.33,.2,1.33);
}
.radio-custom input[type=radio]:checked+label::after {
    -webkit-transform: scale(1,1);
    -ms-transform: scale(1,1);
    -o-transform: scale(1,1);
    transform: scale(1,1);
}
.radio-primary input[type=radio]:checked+label::after {
    border-color: #fff;
}

备注:基于bootstrap,请先引入相应的文件;

参考文献:

https://blog.youkuaiyun.com/baymini0801/article/details/80305733

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值