Chapter 7. Boxes and Borders

Most web designers are familiar with the limitations of HTML as a page layout language, even if they’re not quite aware of it. Think about your page designs for a moment. How many of them depend on tables to get everything where it’s supposed to go? If you’re like the vast majority of web designers, all of your pages use tables. This is because tables can be used to create sidebars, of course, and to set up a complicated structure for an entire page’s appearance, but also to do simpler things, like put text in a colored box with a border.

On the face of it, though, this latter effect is a little simple to be requiring a table. If all that’s needed is a paragraph that has a red border and a yellow background, why should you have to wrap a single-cell table around the paragraph just to get that effect? Wouldn’t it be much easier to simply say that the paragraph itself should have the border and background, and forget about all that table markup?

Thankfully, the authors of CSS felt the same way, so they devoted a great deal of attention to including the ability to define borders for darned near everything a web page can contain. Paragraphs, headings, DIVs, anchors, images, and more can be assigned borders of various types. These borders can be used to set an element apart from others, or accentuate its appearance, or to mark certain kinds of data as having been changed, or to do any number of other things.

In addition to borders, it’s also possible to define ...

Get Cascading Style Sheets: The Definitive Guide 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.