XML technologies / CSS / CSS Cookbook / Page layouts / Asymmetric layouts

(Excerpt from “CSS Kochbuch” by Christopher Schmitt)

Problem

You want to create a flexible asymmetric or organic layout, as shown in the next figure.

Solution

First enclose the content in elements div and give their attributes id appropriate values.

<div id="Kopfzeile">
 [...]
</div>
<div id="kleineSpalte">
 [...]
</div>
<div id="Hauptspalte">
 [...]
</div>
<div id="mittlereSpalte">
 [...]
</div>

Asymmetric content positioning

Figure: Asymmetric content positioning.

Next assign the property position for each column the value absolute. Position the columns with the properties left and top using percentages. Percentages also determine the background image’s position (see the following figure):

body {
 margin: 5px 0 0 5px;
 background-image: url(flower5.jpg);
 background-position: 50% 35%;
 background-repeat: no-repeat;
}
#Kopfzeile {
 position: absolute;
 left: 65%;
 top: 50%;
 width: 125px;
 font-size: 0.7em;
}
#kleineSpalte {
 position: absolute;
 left: 35%;
 width: 15%;
 top: 1%;
 background: #fff;
 font-size: 0.7em;
}
#Hauptspalte {
 position: absolute;
 left: 5%;
 width: 45%;
 top: 40%;
 background: #fff;
 text-align: justify;
 border-width: 0;
 font-size: 1.1em;
}
#mittlereSpalte {
 position: absolute;
 left: 80%;
 width: 20%;
 top: 10%;
 background: #fff;
}

Default page appearance

Figure: Default page appearance.

Discussion

Beyond traditional column-based layouts, CSS offers other ways to design documents. With the properties position, top and left, divide content into small pieces, give them their own styles and arrange them as you wish.

When the browser window is resized, the background image adjusts accordingly because its position is specified as a percentage.

Rather than changing the values of position, top and left manually, use a WYSIWYG program such as Macromedia Dreamweaver to insert the elements div.

For fixed-width columns in an asymmetric or organic layout, use length units instead of percentages to set the exact positions of the content and background image.

body {
 margin: 5px 0 0 5px;
 background-image: url(flower5.jpg);
 background-position: -400px -200px;
 background-repeat: no-repeat;
}
#Kopfzeile {
 position: absolute;
 left: 500px;
 top: 200px;
 width: 125px;
 font-size: 0.7em;
}
#kleineSpalte {
 position: absolute;
 left: 200px;
 width: 125px;
 top: 10px;
 background: #fff;
 font-size: 0.7em;
}
#Hauptspalte {
 position: absolute;
 left: 50px;
 width: 375px;
 top: 175px;
 background: #fff;
 text-align: justify;
 border-width: 0;
 font-size: 1.1em;
}
#mittlereSpalte {
 position: absolute;
 left: 600px;
 width: 150px;
 top: 50px;
 background: #fff;
}

See also

The recipes Non-tiled background images and Repeating background images for defining background images for web pages, and the recipe Using CSS in Adobe Dreamweaver for creating CSS with Adobe Dreamweaver.

  

 

 

 

back to top