View Full Version : Backgrounds

Nov 8th, 2009, 08:32 PM
Is there any way to make a background colour just for text in CSS? I was highlighting someing and decided I actually quite liked how it looked.

http://img35.imageshack.us/img35/5881/style1l.jpg (http://img35.imageshack.us/i/style1l.jpg/) http://img35.imageshack.us/img35/style1l.jpg/1/w659.png (http://g.imageshack.us/img35/style1l.jpg/1/)

When you put it as the background colour, it obviously colours the whole div...

http://img35.imageshack.us/img35/668/style2ki.jpg (http://img35.imageshack.us/i/style2ki.jpg/) http://img35.imageshack.us/img35/style2ki.jpg/1/w670.png (http://g.imageshack.us/img35/style2ki.jpg/1/)

So can you set a colour just for the background of the text in CSS?

Nov 8th, 2009, 08:45 PM
Wrap the required text in span tags and apply the required background to the span:

<p>Some text. <span class="highlight">And some text that's highlighted.</span></p>


This will work because <span> is an inline element, unlike <p> or <div> which are block elements by default.