圆角只是从正方形或圆形中伸出,所以如果我给before
提供白色背景,则收音机的边缘仍然会稍微可见。
input[type=radio] {
box-sizing: border-box;
margin: 0;
padding: 0;
position: relative;
cursor: pointer;
}
input[type=radio]:before {
content: "";
display: block;
width: 16px;
height: 16px;
border: 2px solid grey;
border-radius: 50%;
/* background-color: white; */
position: absolute;
top: 0;
left: 0;
}
> <input type="radio" name="r" checked>
如何使用CSS before
完全隐藏单选按钮?
答案 0 :(得分:1)
我认为使用visibility:hidden
可能会有所帮助,请检查以下内容:
input[type=radio] {
box-sizing: border-box;
margin: 0;
padding: 0;
position: relative;
cursor: pointer;
visibility: hidden;
}
input[type=radio]:before {
content: "";
display: block;
width: 16px;
height: 16px;
border: 2px solid grey;
border-radius: 50%;
/* background-color: white; */
position: absolute;
top: 0;
left: 0;
visibility: visible;
}
input[type=radio]:checked:after {
content: "";
display: block;
width: 10px;
height: 10px;
/* border: 2px solid green; */
border-radius: 50%;
background-color: green;
position: absolute;
top: 5px;
left: 5px;
visibility: visible;
}
<input type="radio" name="r" checked>
答案 1 :(得分:1)
在这里,我尝试了另一种方法来添加span
。试试看。
.customRadio {
position: relative;
}
input[type="radio"] {
opacity: 0;
margin: 0 5px 0 0;
transition: all 0.2s ease 0s;
}
input[type="radio"] + .radioSpan {
background-color: transparent;
border: 1px solid #aaaaaa;
border-radius: 50%;
content: "";
height: 17px;
left: 0;
position: absolute;
top: 2px;
width: 17px;
transition: all 0.3s ease 0s;
}
input[type="radio"]:focus + .radioSpan,
input[type="radio"]:active + .radioSpan {
box-shadow: 0 3px 5px 0 rgba(56, 49, 132, 0.5) !important;
}
input[type="radio"]:checked + .radioSpan {
background-color: #408BF9;
border: 1px solid transparent;
}
input[type="radio"]:checked + .radioSpan::before {
background-color: #ffffff;
border-radius: 50%;
bottom: 0;
content: "";
height: 9px;
left: 0;
margin: auto;
position: absolute;
right: 0;
top: 0;
width: 9px;
z-index: 1;
}
input[type="radio"] ~ .radioText {
display: inline-block;
font-family: 'Roboto', sans-serif;
margin-left: 5px;
text-transform: capitalize;
}
<label class="customRadio">
<input type="radio"name="reportType" value="unsigned-report"/>
<span class="radioSpan"></span>
<span class="radioText">UnSigned Report</span>
</label>
答案 2 :(得分:-1)
请找到以下解决方案: HTML:
<div class="radio">
<input type="radio" name="r" checked>
</div>
CSS:
.radio {
box-sizing: border-box;
margin: 0;
padding: 0;
position: relative;
cursor: pointer;
}
.radio::before {
content: "";
visibility: hidden; // option-1
/* opacity: 0; // option-2 */
/* display: none; //option-3 */
}