javascript - 如何在隐藏的单选按钮上使用键盘选项卡
问题描述
在一个表单中,我有以下通用 html:
<input type="text" autofocus placeholder="Full name" />
<input name="yesno" type="radio" value="Yes" id="yes">
<label for="yes">Yes</label>
<input name="yesno" type="radio" value="No" id="no">
<label for="no">No</label>
在这种形式中,我可以TAB从文本中input
插入单选按钮并使用左/右键选择“是”或“否”。
然后我应用一些样式来使单选按钮符合设计:
input[type="text"] {
height: 60px;
text-indent: 1em;
}
input[type="radio"] {
display: none;
}
input[type="radio"]+label {
color: #106AA2;
background: #fff;
font-weight: 100;
text-align: center;
padding: 1em 2em;
height: auto;
font-size: 1.3em;
border: 1px solid #C5DBE8;
display: inline-block;
letter-spacing: inherit;
vertical-align: middle;
cursor: pointer;
}
input[type="radio"]:checked+label {
background: linear-gradient(#1275B2, #106AA2);
color: #fff;
}
<input type="text" autofocus placeholder="Full name" />
<input name="yesno" type="radio" value="Yes" id="yes">
<label for="yes">Yes</label>
<input name="yesno" type="radio" value="No" id="no">
<label for="no">No</label>
但是,我现在不能再TAB从文本input
到单选按钮了。我知道这是因为我有display:none
他们。
是否有一种跨浏览器的方式可以让用户使用TAB这些单选按钮?
理想情况下,我正在寻找纯 CSS 的解决方案,但是我对 javascript 解决方案持开放态度。
解决方案
不要让它不存在,display: none;
只是缩小它。
您可以设置width
andheight
以0
使输入不可见,但可以使用选项卡。
input[type="text"] {
height: 60px;
text-indent: 1em;
}
input[type="radio"] {
/* display: none; */
width: 0;
height: 0;
}
input[type="radio"]+label {
color: #106AA2;
background: #fff;
font-weight: 100;
text-align: center;
padding: 1em 2em;
height: auto;
font-size: 1.3em;
border: 1px solid #C5DBE8;
display: inline-block;
letter-spacing: inherit;
vertical-align: middle;
cursor: pointer;
}
input[type="radio"]:checked+label {
background: linear-gradient(#1275B2, #106AA2);
color: #fff;
}
<input type="text" autofocus placeholder="Full name" />
<input name="yesno" type="radio" value="Yes" id="yes">
<label for="yes">Yes</label>
<input name="yesno" type="radio" value="No" id="no">
<label for="no">No</label>
推荐阅读
- php - 如何在 DDEV-Local Web 容器中安装 ioncube 加载程序?
- java - 有没有办法用 Java 编写 select...INTO.. 查询的 PL/SQL 代码
- css - Dompdf Laravel 库无法在所有页面中显示页脚
- python-3.x - 如何从包含numpy数组的列表中提取第零个索引值
- google-apps-script - 为什么我得到最后一行有零。我无法删除它们。如果我执行 lastRow-1,我会收到错误
- mongodb - mongodb 3.4.1 上的 BulkWriteResult 是否存在问题
- mongodb - 在 Mongodb 中查找没有字符串“stag”的文档
- python - 将数组划分为几乎相等的块
- javascript - Momentjs 当前时间始终为 0
- java - 将 liferay 7.3(Docker 容器)与 mysql DB(不在容器中)连接