简体   繁体   English

输入字段中占位符文本的颜色

[英]Color of placeholder text in an input field

I have an input field which has a placeholder text. 我有一个输入字段,其中包含占位符文本。 I want one word to be a different color say red, how would would I go about that? 我想要一个字是不同的颜色说红色,我怎么会这样做? Styling a span and surrounding the word with the span didn't work. 使用跨度设置跨度和围绕单词的样式不起作用。

For example on this site, I want to the number in the phrase "Search 649 radio stories" to be red. 例如,在这个网站上,我希望短语“搜索649电台故事”中的数字为红色。

http://66.251.226.207/library http://66.251.226.207/library

I can't tell about a single word, but if you were to style the whole placeholder, then read this. 我不能说一个单词,但如果你要整个占位符,那么请阅读它。

Since placeholders are only supported by WebKit so far, you can use the following css rule for it: 由于占位符目前仅由WebKit支持,因此您可以使用以下css规则

input::-webkit-input-placeholder {
    color: red;
}

For other browsers, as support for placeholder attribute evolves, you'll have to use different rules. 对于其他浏览器,随着对占位符属性的支持的发展,您将不得不使用不同的规则。 For Gecko-based browsers you may want to watch Mozilla's bug 457801 to find out what the final solution will be. 对于基于Gecko的浏览器,您可能需要观看Mozilla的错误457801以找出最终的解决方案。

How about overlaying a div over the input that disappears when you click it (and then directs focus to the input)? 如何将div叠加在单击它时消失的输入(然后将焦点指向输入)? That way you can style the portions of text however you want. 这样,您可以根据需要设置文本部分的样式。

$('#myInputOverlayDiv').click(function() {
    $(this).hide();
    $('#myInputElement').focus();
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM