XML technologies / CSS / CSS Cookbook / Images / Rounded corners (Sliding Doors technique)

(Excerpt from “CSS Kochbuch” by Christopher Schmitt)

Problem

Give rounded corners to columns whose widths can vary.

Solution

Use the Sliding Doors technique popularized by Douglas Bowman.

Create the basic column layout (see the following figure).

Basic column layout

Figure: The basic column layout.

Then create a separate image for each corner, like those in the next figure.

The column design is divided into four images

Figure: The column design is divided into four images.

Wrap the column content in additional elements div:

<div id="box">
  <div id="innerhead">
    <h2>I Met a Girl I&#8217;d Like to Know Better</h2>
  </div>
  <div id="content">
    <div id="innercontent">
      <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>
  </div>
</div>

Now position the background images with CSS (see the next figure). Use the top-left corner as the background of the element div with attribute id “innerhead”; use the top-right corner as the background of the existing element h2. The element div with attribute id “content” receives the bottom-left corner as its background, and the element div with attribute id “innercontent” receives the bottom-right corner.

#innerhead {
 background-image: url(corner_tl.gif);
 background-position: top left;
 background-repeat: no-repeat;
}
h2 {
 background-image: url(corner_tr.gif);
 background-position: top right;
 background-repeat: no-repeat;
 margin: 0;
 padding: 7px;
 border-bottom: 1px solid #999;
 font-size: 1.3em;
 font-weight: normal;
 color: #eee;
}
#content {
 background-image: url(corner_bl.gif);
 background-position: bottom left;
 background-repeat: no-repeat;
}
#innercontent {
 background-image: url(corner_br.gif);
 background-position: bottom right;
 background-repeat: no-repeat;
}

The column corners now appear rounded

Figure: The column corners now appear rounded.

Discussion

This recipe uses several elements div and h2 to anchor the four corner background images. They remain in their intended positions even when the browser window is resized (see the next figure).

Rounded corners stay in position when the column is resized

Figure: The rounded corners stay in their intended positions when the column is resized.

More advanced image editing skills are needed to preserve the design when the column width changes. Edit one side, left or right, extending the images vertically and horizontally. For example, this solution extends the images for the left corners (see the following two figures).

The bottom-right image is 600px wide and over 250px high

Figure: The bottom-right image is 600 pixels wide and over 250 pixels high.

The bottom-left image measures 600 x 600 px

Figure: The bottom-left image measures 600 x 600 pixels.

See also

The recipe Rounded corners (Mountaintop technique) for a simple way to give a column rounded corners.

  

 

 

 

back to top