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).
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’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;
}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;
}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.
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.
Copyright of the German edition © 2007 by O’Reilly Verlag GmbH & Co. KG
You may print the online version for your private use.
Otherwise, this chapter from “CSS Kochbuch” is subject to the same conditions as the bound edition: the work, including all its parts, is protected by copyright. All rights reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
O’Reilly Verlag GmbH & Co. KG, Balthasarstr. 81, 50670 Köln