radio单选框在项目中应用_应用实例

See the Pen <a href="https://codepen.io/chendanaliyuntubiao/pen/VwzzPYX"> radio,checkbox美化应用实例</a> by cdgogo (<a href="https://codepen.io/chendanaliyuntubiao">@chendanaliyuntubiao</a>) on <a href="https://codepen.io">CodePen</a>.

   <div class="container goods-info">
<div class="row goods-tags">
<div class="col-md-2 tag-label">选择版本</div>
<div class="col-md-10">
<div class="tags-select">
<label class="tag-select">
<input type="radio" name="version" value="1">
<span class="name">全网通(2GB 16GB)</span>
</label>
<label class="tag-select">
<input type="radio" name="version" value="2">
<span class="name">全网通(3GB 32GB)</span>
</label>
<label class="tag-select">
<input type="radio" name="version" value="3" disabled>
<span class="name">联通版(2GB 16GB)</span>
</label>
</div>
</div>
</div>
<div class="row goods-tags">
<div class="col-md-2 tag-label">购买方式</div>
<div class="col-md-10">
<div class="tags-select">
<label class="tag-select">
<input type="radio" name="bye-type" value="1">
<span class="name">官方标配</span>
</label>
<label class="tag-select">
<input type="radio" name="bye-type" value="2">
<span class="name">移动优惠购</span>
</label>
<label class="tag-select">
<input type="radio" name="bye-type" value="3" disabled>
<span class="name">联通优惠购</span>
</label>
<label class="tag-select">
<input type="radio" name="bye-type" value="4">
<span class="name">电信优惠购</span>
</label>
</div>
</div>
</div>
</div>

<div class="container sexChecks">
<div class="row">
<div class="col-md-2">您的性别</div>
<div class="col-md-10">
<label>
<input type="radio" name="sex">
<span></span>
</label>
<label>
<input type="radio" name="sex">
<span></span>
</label>
</div>
</div>
</div>


scss样式

.goods-info {
margin-top: 50px;
margin-bottom: 50px;

.tag-label {
padding-top: 7px;
}

.goods-tags {
margin-top: 2rem;
}
}

.tags-select {
font-size: 0;

>.tag-select {
display: inline-block;
font-size: 14px;
margin: 5px;
position: relative;
font-weight: normal;

.name {
display: block;
line-height: 20px;
padding: 8px 10px;
border: 1px solid #ccc;
cursor: pointer;
}

input[type="radio"] {
position: absolute;
opacity: 0;
z-index: -1;

&:checked+.name {
border-color: #e3393c;
}

&:disabled+.name {
background: #eee;
color: #999;
cursor: not-allowed;
}
}
}
}

.sexChecks {
label {
display: inline-block;
position: relative;
margin: 10px;

input {
position: absolute;
opacity: 0;
z-index: -1;
&:checked+span{
border-color: #e3393c;

&::before{
content: "";
width: 10px;
height: 10px;
background: #e3393c;
border-radius: 100%;
position: absolute;
left: 50%;
top: 50%;
margin-left: -5px;
margin-top: -5px;

}
}
}

span {
display: block;
width: 20px;
height: 20px;
border: 1px solid #ddd;
border-radius: 100%;
float: left;
margin-right: 8px;
position: relative;
}
}
}


 ​