XML technologies / CSS / CSS Cookbook / Images / Rounded corners for fixed-width columns

(Excerpt from “CSS Kochbuch” by Christopher Schmitt)

Problem

You want to give fixed-width columns rounded corners.

Solution

Create one combined background image for the top corners and another for the bottom corners (see the following figure).

One image each for top and bottom corners

Figure: One image each for the top and bottom corners.

Enclose the column’s content in an element div:

<div id="box">
  <h2>I Met a Girl I&#8217;d Like to Know Better</h2>
  <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam.</p>
</div>

Place the bottom background image inside the div (see the next figure):

#box {
 width: 214px;
 background-image: url(bkgd_bottom.gif);
 background-position: bottom;
 background-repeat: no-repeat;
}

A background image is defined for the column’s bottom

Figure: A background image is defined for the column’s bottom.

Define the top background image for the element h2 (see the following figure):

h2 {
 background-image: url(bkgd_top.gif);
 backgroung-position: left top;
 background-repeat: no-repeat;
 padding: 7px 7px 3px 7px;
 margin: 0;
 border-bottom: 1px solid #999;
 font-size: 1.3em;
 font-weight: normal;
 color: #eee;
}

A background image is defined for the column’s top

Figure: A background image is defined for the column’s top.

Discussion

To accommodate different text sizes, as shown in the next figure, make the background images longer than the space specified in the design. This example uses graphics 600 pixels long, but lengths over 1,000 pixels are sometimes used to preserve page integrity even with extreme font sizes.

The design remains intact even with large text

Figure: The design remains intact even with large text.

Because column widths use an absolute length such as pixels, the graphics for two corners can be stored in one file. This solution would not work for columns without a fixed width.

See also

The recipes Rounded corners (Sliding Doors technique), Rounded corners (Mountaintop technique) and Rounded corners with JavaScript for creating rounded corners with variable column widths.

  

 

 

 

back to top