XML technologies / CSS / CSS Cookbook / Page elements / Borders

(Excerpt from “CSS Kochbuch” by Christopher Schmitt)

Problem

A web page should have a visible border, as shown in the following figure.

A web page with a border

Figure: A web page with a border.

Solution

Use the property border for the element body:

body {
 margin: 0;
 padding: 1.5em;
 border: 50px #666 ridge;
}

Discussion

The property border is a shorthand property that defines the width, color and style of an element’s border in one step instead of three. To use the individual properties instead, replace the line border: 50px #666 ridge; with the following three lines:

border-width: 50px;
border-color: #666;
border-style: ridge;

Naturally, you can define another border style, such as dotted, dashed or solid (see the following figure).

Border styles available in CSS

Figure: Border styles available in CSS.

As you can see, shadows in the border style groove are reversed compared with the value ridge used in the solution.

Warning: There are minor difficulties in Internet Explorer 5 for Macintosh and Internet Explorer for Windows: the border style dotted appears as rather angular circles, whereas in Netscape 6+, Firefox, Mozilla and Safari it resembles a row of blocks.

Images can also use border styles other than the default solid border. Try the values groove or double, as shown in the next figure:

img.left {
 float: left;
 margin-right: 7px;
 margin-bottom: 3px;
 border: 4px double #666;
}

Image with a double border

Figure: An image with a double border.

See also

The recipe Bordered pull quotes for defining custom border styles for pull quotes.

  

 

 

 

back to top