Set Text Justification
By Stephen Bucaro
Text justification means vertically lining up the first and/or last characters of
every line in a paragraph or on a page. Web browers left justify text by default,
but they leave ragged edges on the right side of paragraphs.
Right text justification can make your webpage look very neat, but you don't get
a free lunch. The browser lines up the ends of sentences by making some lines
longer by inserting extra background pixels between some of the words. So, although
the right edge of your text may look neatly lined up, the interior of your paragraph
will look less neat.
To set text justification, use the CSS text-align property with the value
justify. The easiest way to justify all the text on a webpage is to add the
style attribute to the <body> tag as shown below.
<body style="text-align:justify;">
To set text justification for all paragraph elements on a webpage, put a style
block in the <head> section of your webpage (or in a linked style sheet)
with the paragraph selector as shown below.
<style type="text/css">
p
{
text-align:justify;
}
</style>
Text justification looks even neater when you also set margins. To set 20 pixel
wide left and right margins with text justification use the code shown below. This
code can be used with a fluid layout.
p
{
margin-left:20px;
margin-right:20px;
text-align:justify;
}
The code shown below sets fixed 400 pixel wide paragraphs with text justification.
p
{
width:400px;
text-align:justify;
}
The code shown below sets fixed 400 pixel wide paragraphs with 20 pixel wide left
and right margins and text justification.
p
{
margin-left:20px;
margin-right:20px;
width:400px;
text-align:justify;
}
Web browers left justify text by default. Make your webpage look very neat by setting right text justification.
More CSS Quick Reference: • Set the Text Decoration • Set the Background Properties • Set the Letter Spacing • Set a Background Image's Position • Set the Border Properties • Set the Border Style • Set the Font Style • Set a Fixed Background Image • Set the Line Spacing • Set an Element's Float
|