设置输入的占位符样式,我该怎么做?

时间:2011-06-26 16:42:03

标签: html css html5 input placeholder

  

可能重复:
  Change an input's HTML5 placeholder color with CSS

例如,我有这个:

<input type='search' placeholder='Search' name='q' />

如何使用CSS设置占位符的样式?默认情况下它是灰色的,但我希望它是黑色的。我是否必须使用JavaScript?

2 个答案:

答案 0 :(得分:13)

没有标准方式,并非所有浏览器都支持占位符。

这样的事情应该这样做。:

/* prefix with input if you want, but this will catch input and texatrea */
  ::-webkit-input-placeholder {  color: #000;}
  :-moz-placeholder { color: #000; }

http://jsfiddle.net/CHG46/

如果你想让旧的和新的浏览器支持占位符(IE6-9),似乎有一个jquery插件,这里有一个, https://github.com/mathiasbynens/Placeholder-jQuery-Plugin 但是,我以前没用过它。

答案 1 :(得分:0)

input[placeholder="Search"]
{
color: red
}
相关问题