欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

checkbox和radio 自定义样式

程序员文章站 2024-03-26 11:24:05
...
<div class="radio-box">
    <div class="radio-item">
        <label class="radio-label">
           <input type="radio" value="第一项"}  name="选项">
           <i></i>
           <span>第一项}</span>
        </label>
    </div>
    <div class="radio-item">
        <label class="radio-label">
           <input type="radio" value="第一项"}  name="选项">
           <i></i>
           <span>第一项</span>
        </label>
    </div>
</div>


复选框
<div class="checked-box">
    <div class="checkbox-item">
        <label class="checkbox-label">
            <input type="checkbox" value="篮球"  name="爱好">
            <i></i>
            <span>篮球</span>
        </label>
               
    </div>

    <div class="checkbox-item">
        <label class="checkbox-label">
            <input type="checkbox" value="足球"  name="爱好">
            <i></i>
            <span>足球</span>
        </label>
               
    </div>
</div>

css

.radio-box, .checked-box{
    display: flex;
    flex-flow: wrap;
    align-content: flex-start;
    min-height: 0.4rem;
    margin-bottom: 0.2rem;
}
.radio-item, .checkbox-item{
    width:33%;
    height: 0.4rem;
    display: flex;
    align-items: center;
}
.radio-label, .checkbox-label{
    display: flex;
    align-items: center;
}

.radio-label > span, .checkbox-label > span{
    font-size: 0.2rem;
    color: #757575;
}
.radio-label > input{display: none}
.radio-label > i {
    display: inline-block;
    width: 0.2rem;
    height: 0.2rem;
    vertical-align: center;
    background: url('../img/radio.png') no-repeat center;
    background-size: cover;
    overflow: hidden;
    border-radius: 50%;
    overflow: hidden;
    margin-right: 0.1rem;
    margin-left: 0.02rem;
}
.radio-label > input:checked + i{
    background: url('../img/in-the-radio.png') no-repeat center;
    background-size: cover;
}
.checkbox-label > input{display: none}

.checkbox-label > i {
    display: inline-block;
    width: 0.2rem;
    height: 0.2rem;
    vertical-align: center;
    background: url('../img/check.png') no-repeat center;
    background-size: cover;
    overflow: hidden;
    margin-right: 0.1rem;
    margin-left: 0.02rem;
}
.checkbox-label > input:checked + i{
    
    background: url('../img/checked.png') no-repeat center;
    background-size: cover;
}

效果

checkbox和radio 自定义样式checkbox和radio 自定义样式