Chapter 30. Text Formatting

IN THIS CHAPTER

  • Aligning text

  • Indenting text

  • Controlling white space within text

  • Controlling letter and word spacing

  • Specifying capitalization

  • Using text decorations

  • Autogenerated text

  • Using CSS table properties

  • Controlling table attributes

  • Table layout

  • Aligning and positioning captions

The Web was initially text-based, and text is still a major part of online content today. CSS offers many styles for text formatting, from simple justification to autogenerated text. Although CSS includes options for page layout without tables, it also includes styles for formatting HTML tables. This chapter covers the basics of text and table formatting with CSS.

Aligning Text

Multiple properties in CSS control the formatting of text. Several properties allow you to align text horizontally and vertically — aligning with other pieces of text or other elements around them.

Controlling horizontal alignment

You can use the text-align property to align blocks of text in four basic ways: left, right, center, or full. The following code and the output displayed in Figure 30-1 show the effect of the justification settings:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
  "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
  <title>Text Justification</title>
  <style type="text/css">
    p:left { text-align: left;}
    p.right { text-align: right;}
    p.center { text-align: center;}
    p.full { text-align: justify;}
  </style>
</head> <body> <div style="margin: 50px"> <h3>Left Justified (default)</h3> <p class="left">The ...

Get HTML, XHTML, and CSS Bible, Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.