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!
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! ST<span class="myRedA">A</span>CK OVER FLOW just the '<A' letter is red!
To set the font color in HTML, use the style attribute. The style attribute specifies an inline style for an element. The attribute is used with the HTML <p> tag, with the CSS property color. HTML5 do not support the <font> tag, so the CSS style is used to add font color.
To colored just one word you can use <span style="your style"> WORD</span> . This way you don't have to style the whole paragraph.
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
I just want to add to the solution if you want to change color of only first character then there is a CSS selector element::first-letter
example:
div::first-letter{ color: red; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With