On my friend’s myspace profiles they have a color box around their comments and the text is in diffent colour too. I’ve asked them how they did it but they say they forgot. so how do you do it.
Great question, actually, and one that lets me write about the basics of changing the text color and playing with background colors on MySpace and anywhere else you can add HTML comments!
There are two ways to approach this: you can use the “old school” way of using the FONT tag, or the fancy new CSS way which is far more flexible, but a wee bit more complicated. I prefer the latter because it gives you soooo much power, but let me start by showing you how to change text color with the FONT tag:
That’s the basic approach to making a word, phrase, or paragraph change color. Instead of “blue” you can use a range of different color names, or if you want to put on your geek hat, you can also specify what’s called a hexadecimal RGB value. Those are more complicated — blue would be #0000FF for example – but I also have a handy reference chart to help.
The problem with using the FONT tag is that you can’t change the background color of the text, so you can’t do anything cool like white text in a black box. With CSS you can do that and a ton more. Just about any HTML tag can include CSS formatting information, but a good technique is to use SPAN for inline changes and DIV for block changes. That is, if you want to just change one word in a sentence, that’s a job for SPAN, but if you want to change an entire paragraph to, say, have a different background color, that’s a DIV task.
Here’s that same simple example with CSS:
Not too dissimilar, but what’s cool is that you can now change things like the background as part of that style specification, you just separate attributes with a semicolon:
(#fcc is a light red. #fff is white and #000 is black). Here’s how it looks:
Only one word in this sentence is blue
Nice, isn’t it? Now if we do the exact same sequence with a DIV tag, you’ll see what happens:
Only one word in this sentence is
Quite different. Now you can see how a “block” is really a paragraph. But the DIV tag is quite useful too because you can use it to create attractive blocks of information, like this:
How did I do that? Well, it’s a little bit more complicated, but here’s the source:
The red border is produced with border: 3px solid red, the gray background is produced with background-color:#333, the text is turned white with color:#fff (if you want to use “text-color” it’ll fail, but I admit, I often type that in without thinking and have to fix it too), the spacing between the text and the edge of the box is expanded just a little bit with padding:4px and, finally, I make the text just a little bit larger with font-size:110%.
There are a million ways you can tweak HTML with CSS elements to get the exact result you seek, so it’s far more than I can detail here, but I will tell you that I have a book that steps you through each and every CSS attribute, with examples, that you can find at your local bookstore or here online: Creating Cool Web Sites with HTML, XHTML and CSS. It might be a great way to get the results you seek.