【发布时间】:2019-10-06 00:43:18
【问题描述】:
我使用以下方法创建了自定义复选框/收音机:
<label class="container">One
<input type="checkbox" checked="checked">
<span class="checkmark"></span>
</label>
<label class="container">Two
<input type="checkbox">
<span class="checkmark"></span>
</label>
<label class="container">Three
<input type="checkbox">
<span class="checkmark"></span>
</label>
<label class="container">Four
<input type="checkbox">
<span class="checkmark"></span>
</label>
/* Customize the label (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 checkbox */
.container input {
position: absolute;
opacity: 0;
cursor: pointer;
height: 0;
width: 0;
}
/* Create a custom checkbox */
.checkmark {
position: absolute;
top: 0;
left: 0;
height: 25px;
width: 25px;
background-color: #eee;
}
/* On mouse-over, add a grey background color */
.container:hover input ~ .checkmark {
background-color: #ccc;
}
/* When the checkbox is checked, add a blue background */
.container input:checked ~ .checkmark {
background-color: #2196F3;
}
/* Create the checkmark/indicator (hidden when not checked) */
.checkmark:after {
content: "";
position: absolute;
display: none;
}
/* Show the checkmark when checked */
.container input:checked ~ .checkmark:after {
display: block;
}
/* Style the checkmark/indicator */
.container .checkmark:after {
left: 9px;
top: 5px;
width: 5px;
height: 10px;
border: solid white;
border-width: 0 3px 3px 0;
-webkit-transform: rotate(45deg);
-ms-transform: rotate(45deg);
transform: rotate(45deg);
}
见:https://codepen.io/abluegem/pen/xxxxqez 还有:https://www.w3schools.com/howto/howto_css_custom_checkbox.asp
现在我面临“焦点”状态的问题。这些按钮没有焦点状态。我尝试添加自己的 CSS,但它不起作用。
如您所见,主要元素/标签是没有焦点状态的“标签”。并且有输入标签,但它是隐藏的。
我想知道我是否可以在这些按钮上设置焦点状态。
【问题讨论】:
-
我不明白为什么人们如此沉迷于投票。这是一个有效的问题。 +1。
-
@LGSon 好吧,他是社区的新手,他仍然试图尽可能正确地解释它。他肯定会随着时间的推移而学习,但如果他一开始就被否决,他将无法提高自己并做出进一步的贡献。
-
@Pixel Potter:为了清晰和符合准则,我将示例代码添加到您的问题中。
标签: css checkbox radio-button usability