Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

html

css

textbox

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!

like image 906
bluewonder Avatar asked Jun 27 '13 11:06

bluewonder


People also ask

How do you color individual letters in CSS?

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!

How do you change the color of one text in HTML?

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.

How do I change the color of one word in a paragraph in HTML?

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.


2 Answers

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

like image 58
xec Avatar answered Sep 28 '22 11:09

xec


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; } 
like image 27
Sumit Avatar answered Sep 28 '22 10:09

Sumit