bootstrap拓展:radio按钮,纯css

宰父焕
2023-12-01

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.csdn.net/baymini0801/article/details/80305733

 类似资料: