所以问题是这样的,如何通过仅使用 css 按下用户输入区域附近的标签来使用户输入区域聚焦?
示例: 用户名:某个文本框
*按下“用户名”文本会将焦点引导至文本框。
最佳答案
input:focus {
outline: 0;
border-bottom: 2px solid tomato;
}
input {
border: 0;
height: 30px;
padding: 0 5px;
border-bottom: 2px solid lightgrey;
}
<p>First method simply wrap input with label</p>
<label>Username
<input type="text" placeholder="username">
</label>
<p>Second method by for and id if they are two seprate elements</p>
<label for="username">Username</label>
<input type="text" placeholder="username" id="username">
关于html - 使用CSS通过按标签聚焦输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30012984/