更改文本框 HTML/CSS 中一个字符的颜色

2022-01-13 00:00:00 textbox html css

我正在设计一个网站,我想问你们,如何通过 CSS 更改 HTML 文本框中字符串中的一个字符的颜色?

I'm designing a web site and i would like to ask you guys that, how can I change the color of just one character in a string in a text box of HTML by CSS?

示例:STACK OVER FLOW 只有A"字母是红色的!

example : STACK OVER FLOW just the 'A' letter is red!

谢谢大家

推荐答案

你不能用常规的 <input type="text"><textarea> 元素,但使用普通元素(如 <div><p>)使 contenteditable,你有html/css 格式的所有自由.

You can't do this with a regular <input type="text"> or <textarea> element, but with a normal element (like <div> or <p>) made contenteditable, you have all the freedoms of html/css formatting.

<div contenteditable>
    ST<span style="color: red">A</span>CK OVERFLOW
</div>

http://jsfiddle.net/jVqDJ/

浏览器支持也很好(IE5.5+).在 https://developer.mozilla.org/en-US/阅读更多内容docs/Web/HTML/Content_Editable

The browser support is very good as well (IE5.5+). Read more at https://developer.mozilla.org/en-US/docs/Web/HTML/Content_Editable

相关文章