我正在为自定义单选按钮使用 CSS 代码。如果我使用 html 代码一切正常。但我正在尝试使用asp:RadioButton并且它又呈现了一个标签中的标签。所以css代码不是那样工作的。知道如何解决吗?
自定义 RadioButton HTML 代码(工作正常):
<label class="container">
<input type="radio">
<span class="checkmark"></span>
</label>
RadioButton ASP.NET 在 span 标记中呈现。HTML 的输出(不工作):
<label class="container">
<span>
<input type="radio">
<label>Option One</label>
</span>
<span class="checkmark"></span>
</label>
这是CSS代码
/* The container */
.container {
display: block;
position: relative;
padding-left: 35px;
margin-bottom: 12px;
cursor: pointer;
font-size: 22px;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
/* Hide the browser's default radio button */
.container input {
position: absolute;
opacity: 0;
cursor: pointer;
}
/* Create a custom radio button */
.checkmark {
position: absolute;
top: 0;
left: 0;
height: 25px;
width: 25px;
background-color: #eee;
border-radius: 50%;
}
/* On mouse-over, add a grey background color */
.container:hover input ~ .checkmark {
background-color: #ccc;
}
/* When the radio button is checked, add a blue background */
.container input:checked ~ .checkmark {
background-color: #2196F3;
}
/* Create the indicator (the dot/circle - hidden when not checked) */
.checkmark:after {
content: "";
position: absolute;
display: none;
}
/* Show the indicator (dot/circle) when checked */
.container input:checked ~ .checkmark:after {
display: block;
}
/* Style the indicator (dot/circle) */
.container .checkmark:after {
top: 9px;
left: 9px;
width: 8px;
height: 8px;
border-radius: 50%;
background: white;
}