Hour 13: Borders and Boxes

Within the CSS visual formatting model, all HTML elements are displayed as either inline boxes or block boxes. Property values in CSS rules affect the way these boxes are displayed by applying the styles to the content of each box.

You learned about the box model in Hour 6, "The CSS Box Model," and how you can use the margin, padding, and border properties to affect how a box is displayed. Those core properties allow you to manipulate the edges of the box itself, from the space around the content, to the border around the box, and finally to the space surrounding the content of the box.

In this hour, you'll expand on that knowledge and learn

  • What the four sides of each box are called, and how to refer to them in CSS rules
  • How to use the margin shorthand property to specify margins for specific sides of a box
  • Which margin values to set to center boxes horizontally
  • How to set the padding on each side of a box
  • Which width, color, and line styles can be used on box borders
  • How to set borders for specific sides of the box
  • Which properties and values allow you to hide the display of a box and its contents
  • How to add a message that can be seen only by non-CSS browsers

Sample Code

You can download the sample code from each hour as one package or individual files.

Web Links

There are no Web links for this chapter.

Updates and Errata

There are currently no updates to this hour's content.

CSS in 24 Hours
Teach Yourself CSS in 24 Hours was published in 2002 by SAMS Publishing and provides a solid introduction to Cascading Style Sheets.