javascript - 如何添加不同的占位符颜色

标签 javascript html css twitter-bootstrap

::-webkit-input-placeholder { /* WebKit, Blink, Edge */ color: #909; }

This code change color of all input placeholder. How to make different placeholder colors for different input fields

最佳答案

您需要更具体地说明:
如果您将 ::-webkit-input-placeholder 放入 CSS 中,您将选择所有占位符...但这不是我们想要的

因此使用 :nth-of-type(); 伪类,您可以轻松选择所需的。

有用的文档:

所以代码将是这样的:

/* 1 */

input:nth-of-type(1)::-webkit-input-placeholder {
  color: green;
}


/* 2 */

input:nth-of-type(2)::-webkit-input-placeholder {
  color: blue;
}


/* 3 */

input:nth-of-type(3)::-webkit-input-placeholder {
  color: red;
}
<!-- 1 -->
<input type="text" name="" id="" placeholder="hello world">
<!-- 2 -->
<input type="text" name="" id="" placeholder="hello world">
<!-- 3 -->
<input type="text" name="" id="" placeholder="hello world">

关于javascript - 如何添加不同的占位符颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70637465/

相关文章:

javascript - 如何在 NgStyle 对象中创建后备值

css - Handlebars NodeJS/Koa 脚本/Src 引用

javascript - 从模板发送到组件生命周期方法时数据损坏了吗?

javascript - 当鼠标悬停在 jquery 中时显示按钮的状态

javascript - 使用 AJAX 从表单发送所有数据

javascript - 是否指定了 HTML5 lineJoin 的极端情况

javascript - 我如何知道从 <ul> 中单击了哪个 <li> 元素?

javascript - 单击链接触发操作后,下拉列表不会关闭

javascript - Angular ,ng 类,内部有重复函数

javascript - jQuery $(this) 返回 [object Object]