我必须在点击输入后更改背景颜色并在 <p>
之前元素。只有 input
并不难,但是<p>
是的。
代码
input[type="text"]:focus ~ .prefix{
background-color:#e4ff00 !important;
}
input[type="text"]:focus + .prefix{
background-color:#e4ff00 !important;
}
<div class="inputholder holder50">
<p class="prefix">NIP</p>
<input type="text" value="" name="nip">
</div>
但是没用
最佳答案
如果你在 donwards 中使用 p 它会起作用
<div class="inputholder holder50">
<input type="text" value="" name="nip">
<p class="prefix">NIP</p>
</div>
<style>
input[type="text"]:focus ~ .prefix{
background-color:#e4ff00 !important;
}
input[type="text"]:focus + .prefix{
background-color:#e4ff00 !important;
}
</style>
关于html - css 在元素和 :focus 之前,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37724213/