html - 仅更改输入占位符 * 颜色

标签 html css input placeholder

我有多个输入字段,有些字段是必填 并且必填字段用* 提及,所以我只需要更改输入占位符* 颜色, 不改变整个占位符的颜色检查下图我到底需要什么。

enter image description here
我试过下面的代码来实现这个,但它可以改变占位符的整体颜色

div {
  margin:10px 0px;
}
input {
  width: 200px;
  border: none;
  border-bottom: solid 1px #8d97a0;
  padding: 5px;
  border-radius: 0;
  background: #fff;
  box-shadow: none;
}
::-webkit-input-placeholder {
  color:red;
}
<div>
  <input type="name" name="name" id="name" placeholder="Name *">
</div>
<div>
  <input type="Email" name="email" id="email" placeholder="Email">
</div>
<div>
  <input type="phone" name="phone" id="phone" placeholder="Phone">
</div>
<div>
  <input type="password" name="password" id="password" placeholder="Password *">
</div>

最佳答案

只是placeholder不会给出不同的样式。如果你想要不同的样式,你需要像这样分开。

input {
    width: auto;
}

input + label {
    color: #999;
    font-family: Arial;
    font-size: .8em;
    position: relative;
    left: -166px; 
}

input[required] + label:after {
    content:'*';
    color: red;
}


input[required]:invalid + label {
    display: inline-block;
}

input[required]:valid + label{
    display: none;
}
<div>
  <input type="text" id="name" name="name" required="required" />
  <label for="name">Password</label>
</div>

关于html - 仅更改输入占位符 * 颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47028472/

相关文章:

html - Chrome 中是否存在带有 justify-content : space-between and min-height? 的错误

输入流在对象内结束

javascript - JQuery anchor 链接滚动到错误位置(仅限某些设备)

html - 垂直对齐 : middle an <img> inside a div doesn't centers image

html - 带旋转的 Css3 动画

jquery - 如何使菜单始终附加在顶部

python - 在 while 循环中从键盘读取字符

Linux屏幕输入自动响应

javascript - html,通过document.write动态插入表单

html - 使用 Bootstrap 分层图像