Change color of one character in a text box HTML/C

2019-01-18 10:18发布

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?

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

Thanks guys

标签: html css textbox
5条回答
虎瘦雄心在
2楼-- · 2019-01-18 10:27

you could use bold tags A

css:

b {
font-color: red;
}
查看更多
一夜七次
3楼-- · 2019-01-18 10:37

From css you can only change an elements property so you need to insert the letter "A" in another element like this:

ST<span>A</span>CK OVER FLOW just the 'A' letter is red!

And the CSS part is

span{
   color:#FF0000;
}

Or attach a class to it like this

ST<span class="myRedA">A</span>CK OVER FLOW just the '<A' letter is red!

CSS:

span.myRedA{
       color:#FF0000;
    }
查看更多
兄弟一词,经得起流年.
4楼-- · 2019-01-18 10:44

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/

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

查看更多
兄弟一词,经得起流年.
5楼-- · 2019-01-18 10:44
<font color="#colors">text text text</font> 
查看更多
唯我独甜
6楼-- · 2019-01-18 10:49

The question is - what did you mean by "text box"? Did you mean simple text on a page, or editable text like input type="text" or textarea? If you meant simple text, then the previous answers will do the job. But in case of editable text, it is impossible to achieve by css.

查看更多
登录 后发表回答