Tech Musings

Text alignment (left, right, left, right, left, right....)

No, we're not talking about drill sergeant orders here (left, right, left, right...). Rather we are going to look at the alternative to the html attribute align="xxxxxxx".

The CSS property, text-align lets you control where the text goes in the HTML tag it is applied to. Possible values are left, right, center, and justify. In the following examples, I'm using a
tag with a border to better show the alignment. First we have text-align:center.

This text is going to be aligned center within it's containing div tag so you can see how it lays out

Let's show the other forms for comparison:

This text is going to be aligned right within it's containing div tag so you can see how it lays out

This text is going to be justified within it's containing div tag so you can see how it lays out

and for completeness, let's see left alignment which is the default

This text is going to be aligned left within it's containing div tag so you can see how it lays out

I forced the justified case
to have a width:20% so that you could better see the justification taking place. Usually, justified text is harder to read on computers so try to leave it for books where a ragged right margin is not desired.

Cheers
"I am an eBay employee. The opinions expressed in my blog are my own, and not eBay's."


About eBay | Announcements | Security Center | eBay Toolbar | Policies | Government Relations | Site Map | Help
Copyright © 1995-2008 eBay Inc. All Rights Reserved. Designated trademarks and brands are the property of their respective owners. Use of this Web site constitutes acceptance of the eBay User Agreement and Privacy Policy.
eBay official time