尝试将焦点放在样式化的选择和嵌套在 div 中的其他输入:
<label for="focusedSelect">I want to Focus on You</label>
<div class="styled-select">
<select id="focusedSelect">
<option value="1">Won</option>
<option value="2">Too</option>
</select>
</div>
<label for="focusedInput>Let me Focus on You Too</label>
<div class="styled-inputs">
<input id="focusedInput" type="text"/>
</div>
点击标签不会将焦点放在嵌套 div 的输入或选择上。
最佳答案
你的代码对我来说工作正常,我只需要修正一些错误:
<label for="focusedSelect">I want to Focus on You</label>
<div class=" styled-select">
<select id="focusedSelect">
<option value="1 ">Won</option>
<option value="2 ">Too</option>
</select>
</div>
<label for="focusedInput">Let me Focus on You Too</label>
<div class="styled-inputs">
<input id="focusedInput" type="text" />
</div>
您缺少标签“for”属性的尾随引号以及结束符 <label>
的尾随大于号 (>) 字符第二个输入的元素。
关于css - 标签输入或标签选择,如果输入或选择嵌套在 div 中,则焦点不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38312801/