为输入的占位符设置样式,我该如何做? [英] Styling the placeholder of an input, how can I do this?

查看:197
本文介绍了为输入的占位符设置样式,我该如何做?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

使用CSS更改输入的HTML5占位符颜色

例如,我有:

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

如何使用CSS样式化占位符?默认情况下它是灰色的,但我想它是黑色的。

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?

推荐答案

没有标准的方法,并不是每个浏览器都支持占位符。

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

这样应该可以。

/* 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
然而,我以前没有使用它。

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.

这篇关于为输入的占位符设置样式,我该如何做?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆