开发者

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

开发者 https://www.devze.com 2023-03-15 07:03 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: Change an input's HTML5 placeholder color with CSS
This question already has answers here: Closed 11 years ago.

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 defa开发者_如何转开发ult it's gray, but I'd like it to be black. Do I have to use JavaScript instead?


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.


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

精彩评论

暂无评论...
验证码 换一张
取 消