【发布时间】:2021-11-01 16:20:03
【问题描述】:
input {
background: transparent;
position: relative;
}
label {
color: black;
}
input:focus + label {
color: red !important;
border: 1px solid white;
}
<div class="input-box d-flex flex-column">
<label for="name" class="py-2">Your Name</label>
<input class="py-2 border-0 text-white" id="name" type="text" />
</div>
当我关注表单的输入时,我想更改标签文本颜色。
【问题讨论】:
-
只需将标签放在输入下方。你很高兴
-
将输入包装在标签内并使用
label:focus-within input