Value/Placeholder - different styling for words

家住魔仙堡 提交于 2019-12-01 20:50:29

问题


I'm having problem with placeholders. I want to ask, is there possibility to style value in input fields but in the way to style words of that value different.

For example, if we have input field which have initial value "First Name" i want to have green color for "First", and red color for "Name" (this is just an example).

Is this even possible?

Note: Im using value as "placeholder" (instead of placeholder html attribute) because of ie.

<input type="text" value="First Name" onFocus="if (this.value == 'First Name') {this.value = '';}" onBlur="if (this.value == '') {this.value = 'First Name';}" />

回答1:


unfortunately its not possible. when it comes to styling the form elements, there are many hindrances, color can be set to for an element not chracters, try this:

http://jsfiddle.net/Fgd2e/1/




回答2:


You may change the color of an input using the color style attribute. Having separate colors for each word is much harder. You need to have an overlay that displays the right colors. Besides, the cursor would disappear, so that the user wouldn't know where he currently is.



来源:https://stackoverflow.com/questions/10461491/value-placeholder-different-styling-for-words

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