【问题标题】:Styling the placeholder of an input, how can I do this? [duplicate]样式化输入的占位符,我该怎么做? [复制]
【发布时间】:2011-09-23 00:52:48
【问题描述】:

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

例如,我有这个:

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

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

【问题讨论】:

  • 很明显,这已经被问到了。几次。但对于喜欢 stackoverflow 却落后于 html5 所提供的一切的人来说,这仍然是一个很好的问题。 stackoverflow.com/questions/2610497/…

标签: css html input placeholder


【解决方案1】:

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

应该这样做。

/* 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 但是,我以前没有使用过。

【讨论】:

    【解决方案2】:
    input[placeholder="Search"]
    {
    color: red
    }
    

    【讨论】:

    猜你喜欢
    • 2017-04-07
    • 2013-01-15
    • 2020-12-19
    • 2015-11-13
    • 2019-01-27
    • 2014-07-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多