我需要单选按钮具有正方形格式,以保持每个按钮的背景色。
我尝试添加“ .custom-radios输入[type =“ radio”] +标签跨度”:
-webkit-appearance:复选框;
-moz-appearance:复选框;
-ms-appearance:复选框;
但这会带走背景色。
.custom-radios div {
display: inline-block;
}
.custom-radios input[type="radio"] {
display: none;
}
.custom-radios input[type="radio"] + label {
color: #333;
font-family: Arial, sans-serif;
font-size: 14px;
}
.custom-radios input[type="radio"] + label span {
display: inline-block;
width: 25px;
height: 25px;
margin: -1px 4px 0 0;
vertical-align: middle;
cursor: pointer;
border-radius: 50%;
border: 2px solid #fff;
box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.33);
background-repeat: no-repeat;
background-position: center;
text-align: center;
line-height: 25px;
}
.custom-radios input[type="radio"] + label span img {
opacity: 0;
transition: all 0.3s ease;
}
.custom-radios input[type="radio"]#color-3 + label span {
background-color: #f1c40f;
}
.custom-radios input[type="radio"]#color-4 + label span {
background-color: #e74c3c;
}
.custom-radios input[type="radio"]:checked + label span img {
opacity: 1;
}
<div class="custom-radios">
<div>
<input type="radio" id="color-3" name="color" value="color-3">
<label for="color-3">
<span>
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/242518/check-icn.svg" alt="Checked Icon" />
</span>
</label>
</div>
<div>
<input type="radio" id="color-4" name="color" value="color-4">
<label for="color-4">
<span>
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/242518/check-icn.svg" alt="Checked Icon" />
</span>
</label>
</div>
</div>
答案 0 :(得分:1)
删除边框半径:50%;
.custom-radios div {
display: inline-block;
}
.custom-radios input[type="radio"] {
display: none;
}
.custom-radios input[type="radio"] + label {
color: #333;
font-family: Arial, sans-serif;
font-size: 14px;
}
.custom-radios input[type="radio"] + label span {
display: inline-block;
width: 25px;
height: 25px;
margin: -1px 4px 0 0;
vertical-align: middle;
cursor: pointer;
/*border-radius: 50%;*/
border: 2px solid #fff;
box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.33);
background-repeat: no-repeat;
background-position: center;
text-align: center;
line-height: 25px;
}
.custom-radios input[type="radio"] + label span img {
opacity: 0;
transition: all 0.3s ease;
}
.custom-radios input[type="radio"]#color-3 + label span {
background-color: #f1c40f;
}
.custom-radios input[type="radio"]#color-4 + label span {
background-color: #e74c3c;
}
.custom-radios input[type="radio"]:checked + label span img {
opacity: 1;
}
<div class="custom-radios">
<div>
<input type="radio" id="color-3" name="color" value="color-3">
<label for="color-3">
<span>
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/242518/check-icn.svg" alt="Checked Icon" />
</span>
</label>
</div>
<div>
<input type="radio" id="color-4" name="color" value="color-4">
<label for="color-4">
<span>
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/242518/check-icn.svg" alt="Checked Icon" />
</span>
</label>
</div>
</div>
答案 1 :(得分:1)
只需将边界半径设为0%
.custom-radios input[type="radio"] + label span {
display: inline-block;
width: 25px;
height: 25px;
margin: -1px 4px 0 0;
vertical-align: middle;
cursor: pointer;
border-radius: 0%;
border: 2px solid #fff;
box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.33);
background-repeat: no-repeat;
background-position: center;
text-align: center;
line-height: 25px;
}