繁体   English   中英

输入文本时在文本区域中消失的背景图像

[英]Disappearing background image in textarea when entering text

我想将图像设置为 HTML 中的textarea标签的背景,然后在用户输入一些文本时使其消失,同时具有新的背景(在这种情况下只是一种颜色)。 我期望的行为类似于placeholder属性发生的行为,但对于背景。 我还发现它对jQuery是可行的,但我没有使用它
索引.html:

<html>
  <head>
  <link rel="stylesheet" href="style.css">
  <body>
    <textarea id="code"></textarea>
  </body>

样式.css

#code {
  color: white;
  background-color: black;
  background: url(logo.png) center center no-repeat;
}

 #code { color: white; background-color: black; } #code:placeholder-shown { background: url(https://leanfrontiers.com/wp-content/uploads/2018/12/logo-placeholder-png.png) center center no-repeat; } #code:not(:placeholder-shown) { background-color: red; }
 <textarea id="code" placeholder=" "></textarea>

试试这个#code:active { background: none; } #code:active { background: none; }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM