Styling the placeholder of an input, how can I do this? [duplicate]

人盡茶涼 提交于 2019-12-08 14:38:07

问题


Possible Duplicate:
Change an input's HTML5 placeholder color with CSS

For example, I have this:

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

How can I style the placeholder with CSS? By default it's gray, but I'd like it to be black. Do I have to use JavaScript instead?


回答1:


no standard way, and not every browser supports place holder yet.

Something like this should do it.:

/* 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/

if you want old and new browsers to support placeholder (IE6-9) there appears to be a jquery plugin(s), here is one, https://github.com/mathiasbynens/Placeholder-jQuery-Plugin however, I have not used it before.




回答2:


input[placeholder="Search"]
{
color: red
}


来源:https://stackoverflow.com/questions/6485247/styling-the-placeholder-of-an-input-how-can-i-do-this

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!