Some people asked about how I did the fancy formatting in a recent post. This is a mini-tutorial on the CSS parts of things. It assumes you have done some HTML editing.
There is a special additional stuff you can do using something called CSS (Cascading Style Sheets). CSS is a whole extra language for specifying layout and can be piggy-backed onto HTML text by using a style attribute on various elements. You don't have to understand all of CSS to know how to do some cool things. Just take a look at some examples:
Use <p style="text-indent: 2em;">Your text here.</p> to create a paragraph that has 2 ems of indentation in the first line only. An "em" is a funny unit that is the width of the capital M in the current font. That character is usually the widest in the font, and so an em is considered to be a "wide space" in any font. This paragraph is indented 2 ems.
Don't be perplexed,
<p style="text-align: center;">this will center your text.</p>
It's more clear from afar,
if you use <br />
which forces a line break
to shorter the lines make.
The centering will show 'em.
You've got a great poem.
So work out a rhyme
Or just have a good time.
Use <p style="text-align: right;">Your text here.</p>
to align to the right instead of the left.
Not that you'd want to do that a lot here
since Salon leans left.
Draw a border with the border attribute. A solid black border one pixel wide (a pixel being a single screen dot, the smallest your monitor can display) is done with:
<p style="border: 1px solid black;">Your text here.</p>
That looks crowded, though, doesn't it. Usually you want padding around the text inside the border. Let's add about 5 pixels of padding:
<p style="border: 1px solid black; padding: 5px;">Your text here.</p>
You can collect several paragraphs into a group called a division using a “div” element:
<div>...multiple paragraphs here...</div>
A useful feature of a div is that it can have a background color. For example, in a style attribute, you can say “background: silver;” in order to see the text on a silver background.
Having done that, you can put a style attribute on the division that will apply to each of the things inside it. For example, this paragraph and the one before it are grouped into a div that looks like this:
<div style="border: 1px solid black; padding: 5px; text-indent: 2em; background: silver;">
<p>You can collect...</p>
<p>A useful feature...</p>
<p>Having done that...</p>
</div>
You can specify the font to use, but beware: Just about everyone on the net has different fonts on their computer, so often this doesn't work or has variable effect. You specify the “font-family” in a style setting, and the recommended value given is a list of fonts to try in order from left to right until one is found. For example, to get a font without serifs (the little horizontal bar at the top and bottom of a capitalized “i” for example), you specify
style="font-family: Arial, Helvetica, sans-serif;"
(Trivia: “sans” is French for “without” if you didn't know.)
To get a font with serifs, try:
style="font-family: Times New Roman, Times, serif;"
But as long as you put in these fallbacks, you can try others. For example, if ou write:
style="font-family: Goudy Old Style, Goudy, Bookman, Century Schoolbook, Times New Roman, Times Roman, Times, serif;"
you should get Goudy Old Style (if it's present on the end-user's machine), or Goudy (if it's present), or Bookman. If this paragraph you're reading looks different than others before it, that's because you've got one of those fonts. I set up this paragraph using:
<p style="font-family: Goudy Old Style, Goudy, Bookman, Century Schoolbook, Times New Roman, Times Roman, Times, serif;">You can specify...</p>
Some colors are possible to name. For those that are not, you can use a “#” character followed by 6 letters which are hexadecimal digits. If you don't know what a hexadecimal digit is, don't get scared. It just means that letters are bigger than numbers and that f is the biggest. So ffffff is the biggest six-digit number and 000000 is the smallest. You're almost there. Don't panic. Each pair of digits represents a primary color. The first two are red, the next two blue, and the next two green. So 000000 means no red, no blue, no green (the color ends up black, by the way). ffffff means lots of red, lots of blue, and lots of green (and ends up being white). 00ffff has no red but lots of blue and green. That's going to come out aqua (or some might say cyan, but aqua is the official name). If you don't know a lot about mixing colors of light, it's not like paint. Yellow is made up of red and green in light. (Trust me.) So ffff00 is yellow. But if you put in more blue, you'll get a color closer to white, which means a pastel yellow. ffffbb for example. This paragraph is that pastel yellow color, #ffffbb.

You can make text flow around a picture or a div by using the CSS directive “float: right;” or “float: left;”. Put the thing you want to be flowed around first, then the text that follows will do that. You can set the width of a div with a width specification. A normal Open Salon column is 485px wide, so if you use, for example, 200px, you'll get just under half a column. The pumpkin that is featured in this column is set to be 50 pixels wide and because no height is set will appear proportional height. A margin of 5 pixels is added around the pumpkin outside of its border so it doesn't run into the text. (The margin is like the padding, but margin is on the outside of the border instead of the inside.) That pumpkin was specified by:
<img style="float: right; width: 50px; margin: 5px; border: 2px solid black;"
src="http://open.salon.com/files/pumpkin-face1221728008.gif" mce_src="http://open.salon.com/files/pumpkin-face1221728008.gif"
alt="pumpkin face" />
A div or paragraph can be resticted to a particular width, forcing the item to be that particular width rather than the default of 485px. This paragraph is 300px wide, as done by:
<p style="width: 300px;">
Another thing that can be set to a width is a horizontal rule, <hr />.
You can set its width explicitly. You can also say whether the short line should appear left, center, or right.
<hr style="width: 150px; text-align: center;" />
In fact you can give the rule a height and a color if you like:
<hr style="width: 200px; height: 5px; text-align: left; color: green;" />
This is one last example, pulling it all together. Hopefully it will demonstrate the use of a custom color as well as a custom font.
The div starts with:
<div style="border: 1px solid black; margin: 20px; padding: 10px; text-indent: 2em; background: #ffffbb; font-family: Goudy Old Style, Goudy, Bookman, Century Schoolbook, Times New Roman, Times Roman, Times, serif;">
And, of course, the custom indentation.
You can override any of those attributes on a per-paragraph basis, of course. The “Sincerely” below is done with:
<p style="text-indent: 0em;">Sincerely,</p>
Sincerely,
Kent Pitman
The official CSS specification can be found at w3.org.
If you got value from this post, please "rate" it.


Salon.com
Comments
Biblio, if you run into questions, feel free to post them.
Their choice to do the editing of markup is not a bad thing, as it retains the quality of the site in the face of ordinary mortals who if they try this by hand may mess things up pretty badly by making typos... it repairs a lot of would-be damage. I just think there should be fewer context variations and that the rules should be published so that people can understand them better.
Greg
rated
On another day when I am feeling smarter, I will tackle this and be fancy too!
BTW, have you noticed the new look to the cover? Many more cover stories and an elongated activity feed for new posts and rated stories? Looks good.
rated and always appreciate your help in these matters.
I also found one other handy work-around last night. If you use a blog platform (e.g. TypePad) that shows a post in both HTM and Rich Text, you can display the HTM version, and copy/paste the code right into your blog at OS [using the HTM option]. It will come up on the OS side with all formatting (and images) intact, where you can preview and tweak before you hit "publish."
I don't know if this also works with other blog platforms or offline editing tools, but I imagine it should. This little discovery may save me a ton o' tme, but I will keep your post as a great crib sheet too ;->
Kudos.
I've managed to copy/paste some code that does what I want in the OS blog editor, but when I save and preview, all table formatting is gone.
:-(
You seemed like a good candidate user to ask here. My HTML skills are basic, but I'm a quick learner.
Oh yeah.... rated!
Thanks so much for responding Kent.
I should be more studious, at the the very least I'd like to be able to post stuff so that extended dialogue is tabbed in. So close, and yet so far.
I know, I just need to concentrate...
http://open.salon.com/blog/zumalicious/2009/05/15/orgasmic_explosion_of_colorific_madness
Next, I'm going to play with the fancy boxes and indentation!
Lezlie