gpt4 book ai didi

html - 如何通过 CSS 为聚焦输入框上的标签着色?

转载 作者:太空宇宙 更新时间:2023-11-03 20:29:04 24 4
gpt4 key购买 nike

我想要着色标签对输入焦点的影响。就像我关注输入框时,标签颜色应该变为蓝色。但这不起作用,我想知道为什么以及如何解决这个问题?

.test-label{
color: purple;
}
.test-box:focus .test-label{
color: blue !important;
}
<form>
<label class = "test-label">Label</label>
<br />
<input type = "text" class = "test-box">
</form>

最佳答案

您可以使用 focus-within为此。

Note it has limited support.

.test-label {
color: purple;
}

form:focus-within .test-label {
color: blue;
}
<form>
<label class="test-label">Label</label>
<br />
<input type="text" class="test-box">
</form>

关于html - 如何通过 CSS 为聚焦输入框上的标签着色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46713981/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com