tags:

views:

85

answers:

4

Hey there!

I was wondering what is the best way to change the font colour of some text that appears halfway through a paragraph.

For example, I have a paragraph of white text, but I want a couple of words in the middle of the paragraph to be orange so that they stand out, but then carry on with white text after that, what would be the best way of achieving this?

Thanks in advance!

+6  A: 
<span style="color:orange;">orange text</span>

Is the only way I know of barring the font tag.

Novikov
Okay thanks for the quick response!
One should avoid hard coding the color inside the html itself.
jsbueno
@Novikov - eek. The font tag -- go wash your hands after typing that.
Joel Etherton
I shouldn't have mentioned the font tag, I'm expecting a mob at my doorstep any second now. :P
Novikov
+1  A: 

wrap a <span> around those words and style with the appropriate color

now is the time for <span style='color:orange'>all good men</span> to come to the
Scott Evernden
+13  A: 

<span> will allow you to style text, but it adds no semantic content.

As you're emphasizing some text, it sounds like you'd be better served by wrapping the text in <em></em> and using CSS to change the color of the <em> element. For example:

CSS

.description {
  color: #fff;
}

.description em {
  color: #ffa500;
}

Markup

<p class="description">Lorem ipsum dolor sit amet, consectetur 
adipiscing elit. Sed hendrerit mollis varius. Etiam ornare placerat 
massa, <em>eget vulputate tellus fermentum.</em></p>

In fact, I'd go to great pains to avoid the <span> element, as it's completely meaningless to everything that doesn't render your style sheet (bots, screen readers, luddites who disable styles, parsers, etc.) or renders it in unexpected ways (personal style sheets). In many ways, it's no better than using the <font> element.

Mark Trapp
Unless I'm mistaken, this will cause the ".description em" to be orange in addition to being italicised. To have an <em> _just_ be orange, you will have to tell the browser not to make the <em> italics, by making the second block ".description em {color: #ffa500; font-style: normal; }" (whitespace removed by comment system :( )
Hober
@Hober: assuming a CSS reset hasn't been employed. As you've shown, default styles aren't an impediment to employing semantically-useful markup.
Mark Trapp
+3  A: 

Nornally the tag is used for that, with a change in style.

Like <p>This is my text <span class="highlight"> and these words are different</span></p>,

You set the css in the header (or rather, in a separate css file) to make your "highlight" text assume the color you wish.

(e.g.: with

<style type="text/css">
  .highlight {color: orange}

</style>

in the header. Avoid using the tag <font /> for that at all costs. :-)

jsbueno