如何更改 <input/> 的占位符颜色?
How to change <input/>'s placeholder color?
我用样式表和 <input/>
尝试了以下操作,但占位符的颜色仍然没有改变并保持默认颜色。我做错了吗?
我的 css 样式表:
#input-field {
background-color: rgba(255,255,255,0.1);
border: 0;
border-radius: 5px;
width: 150px;
height: 40px;
padding: 12px;
box-shadow: none;
color: rgba(255,255,255,0.8);
}
:-webkit-input-placeholder { /* WebKit, Blink, Edge */
color: blue;
}
:-moz-placeholder { /* Mozilla Firefox 4 to 18 */
color: blue;
opacity: 1;
}
::-moz-placeholder { /* Mozilla Firefox 19+ */
color: blue;
opacity: 1;
}
:-ms-input-placeholder { /* Internet Explorer 10-11 */
color: blue;
}
还有我的<input/>
:
<input
className="form-control"
id="input-field"
placeholder='Change This Color'
/>
webkit 需要两个冒号::
#input-field {
font-family: serif;
background-color: rgba(255,255,255,0.1);
border: 0;
border-radius: 5px;
width: 150px;
height: 40px;
padding: 12px;
box-shadow: none;
color: rgba(255,255,255,0.8);
}
::-webkit-input-placeholder {
color: blue;
}
:-moz-placeholder { /* Firefox 18- */
color: blue;
opacity: 1;
}
::-moz-placeholder { /* Firefox 19+ */
color: blue;
opacity: 1;
}
:-ms-input-placeholder {
color: blue;
}
<input
className="form-control"
id="input-field"
placeholder='Change This Color'
/>
更改字体系列添加 font-family: serif;
到 #input-field
在您的 Html 页面中
<input
class="form-control"
id="input-field"
placeholder='Change This Color'
/>
在您的 css 页面中
.form-control::-webkit-input-placeholder {
color: red;
width: 250px;
font-family:Helvetica Neue;
}
font-family:Helvetica Neue
为我工作 here is the link
干脆把这段代码记下来。你的错误是你忘了加冒号。
我花了很多时间在这上面,但归结为在 :-webkit-input-placeholder
之后加上另一个冒号,使其成为 ::-webkit-input-placeholder
.
我刚刚发现其他人的回答与我完全相同,我并不是要复制他们,因为我自己想出来了。
看看完整的代码。 PS 我让它看起来像 font-family
的草书。
#input-field {
background-color: rgba(255, 255, 255, 0.1);
border: 0;
border-radius: 5px;
width: 150px;
height: 40px;
padding: 12px;
color: red;
box-shadow: none;
font-family: cursive;
}
::-webkit-input-placeholder {
color: blue;
font-family: cursive;
}
:-moz-placeholder {
/* Firefox 18- */
color: red;
opacity: 1;
}
::-moz-placeholder {
/* Firefox 19+ */
color: red;
opacity: 1;
}
:-ms-input-placeholder {
color: red;
}
<input className="form-control" id="input-field" placeholder='Change This Color' />
我用样式表和 <input/>
尝试了以下操作,但占位符的颜色仍然没有改变并保持默认颜色。我做错了吗?
我的 css 样式表:
#input-field {
background-color: rgba(255,255,255,0.1);
border: 0;
border-radius: 5px;
width: 150px;
height: 40px;
padding: 12px;
box-shadow: none;
color: rgba(255,255,255,0.8);
}
:-webkit-input-placeholder { /* WebKit, Blink, Edge */
color: blue;
}
:-moz-placeholder { /* Mozilla Firefox 4 to 18 */
color: blue;
opacity: 1;
}
::-moz-placeholder { /* Mozilla Firefox 19+ */
color: blue;
opacity: 1;
}
:-ms-input-placeholder { /* Internet Explorer 10-11 */
color: blue;
}
还有我的<input/>
:
<input
className="form-control"
id="input-field"
placeholder='Change This Color'
/>
webkit 需要两个冒号::
#input-field {
font-family: serif;
background-color: rgba(255,255,255,0.1);
border: 0;
border-radius: 5px;
width: 150px;
height: 40px;
padding: 12px;
box-shadow: none;
color: rgba(255,255,255,0.8);
}
::-webkit-input-placeholder {
color: blue;
}
:-moz-placeholder { /* Firefox 18- */
color: blue;
opacity: 1;
}
::-moz-placeholder { /* Firefox 19+ */
color: blue;
opacity: 1;
}
:-ms-input-placeholder {
color: blue;
}
<input
className="form-control"
id="input-field"
placeholder='Change This Color'
/>
更改字体系列添加 font-family: serif;
到 #input-field
在您的 Html 页面中
<input
class="form-control"
id="input-field"
placeholder='Change This Color'
/>
在您的 css 页面中
.form-control::-webkit-input-placeholder {
color: red;
width: 250px;
font-family:Helvetica Neue;
}
font-family:Helvetica Neue
为我工作 here is the link
干脆把这段代码记下来。你的错误是你忘了加冒号。
我花了很多时间在这上面,但归结为在 :-webkit-input-placeholder
之后加上另一个冒号,使其成为 ::-webkit-input-placeholder
.
我刚刚发现其他人的回答与我完全相同,我并不是要复制他们,因为我自己想出来了。
看看完整的代码。 PS 我让它看起来像 font-family
的草书。
#input-field {
background-color: rgba(255, 255, 255, 0.1);
border: 0;
border-radius: 5px;
width: 150px;
height: 40px;
padding: 12px;
color: red;
box-shadow: none;
font-family: cursive;
}
::-webkit-input-placeholder {
color: blue;
font-family: cursive;
}
:-moz-placeholder {
/* Firefox 18- */
color: red;
opacity: 1;
}
::-moz-placeholder {
/* Firefox 19+ */
color: red;
opacity: 1;
}
:-ms-input-placeholder {
color: red;
}
<input className="form-control" id="input-field" placeholder='Change This Color' />