by eturo
Text
Formatting and adding style to text is a key issue for any web designer.
In this lesson you will be introduced to the amazing opportunities CSS gives
you to add layout to text. The following properties will be described:
¤ Text indention
[text-indent]
The property text-indent
allows you to add an elegant touch to text paragraphs by applying an indent to
the first line of the paragraph. In the example below a 30px is applied to all text paragraphs marked with
:
p {
text-indent: 30px;
}
¤ Text alignment
[text-align]
The CSS property text-align
corresponds to the attribute align used in old versions of HTML. Text can
either be aligned to the left,
to the right or centred. In addition to this, the
value justify will stretch each
line so that both the right and left margins are straight. You know this layout
from for example newspapers and magazines.
In the example
below the text in table headings is aligned to the right while the
table data are centred. In addition, normal text paragraphs are
justified:
th {
text-align: right;
}
td {
text-align: center;
}
p {
text-align: justify;
}
¤ Text decoration
[text-decoration]
The property text-decoration
makes it is possible to add different "decorations" or
"effects" to text. For example, you can underline the text, have a
line through or above the text, etc. In the following example,
are underlined headlines,
are headlines with a line above the text and
are headlines with a line though the text.
h1 {
text-decoration: underline;
}
h2 {
text-decoration: overline;
}
h3 {
text-decoration: line-through;
}
¤ Letter space
[letter-spacing]
The spacing between
text characters can be specified using the property letter-spacing. The value
of the property is simply the desired width. For example, if you want a spacing
of 3px between the letters in a
text paragraph
and 6px
between letters in headlines
the code below could be used.
h1 {
letter-spacing: 6px;
}
p {
letter-spacing: 3px;
}
¤ Text transformation
[text-transform]
The text-transform
property controls the capitalization of a text. You can choose to capitalize, use uppercase or lowercase regardless of how the original text is looks in the HTML
code.
An example could be
the word "headline" which can be presented to the user as
"HEADLINE" or "Headline". There are four possible values
for text-transform:
o capitalize
§ Capitalizes the
first letter of each word. For example: "john doe" will be "John
Doe".
o uppercase
§ Converts all
letters to uppercase. For example: "john doe" will be "JOHN
DOE".
o lowercase
§ Converts all
letters to lowercase. For example: "JOHN DOE" will be "john
doe".
o none
§ No transformations
- the text is presented as it appears in the HTML code.
As an example, we
will use a list of names. The names are all marked with
Try to take a look
at the HTML code for this example and you will see that the text actually is in
lowercase.
h1 {
text-transform: uppercase;
}
li {
text-transform: capitalize;
}