html - css 在元素和 :focus 之前

标签 html css focus

我必须在点击输入后更改背景颜色并在 <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/

相关文章:

html - CSS - 如何仅显示顶部 div 的 %,两个相同的 div 相互堆叠

c++ - 如何防止窗口被停用?

Java 文本字段焦点

单击 <button> 的 CSS 伪类

python - 是否可以在 Gtk 中更改单选按钮颜色?

javascript - 将不透明的图像绘制到 Canvas 上

javascript - 如何模糊 iframe?

html - 如何在 div 中做响应式 HTML Canvas

jquery - 使用 jQuery 循环遍历 JSON 结果

javascript - 在 Javascript 中解析 html 以进行 Canvas 渲染