XML technologies / CSS / Advanced websites with CSS / Fixed-width layouts / The content area
(Excerpt from “CSS − Advanced websites with Cascading Stylesheets” by Rachel Andrew & Dan Shafer)
With the header design finished, we will now turn to the content area. This entire area is already contained in the element div with ID #content. In the graphic design this area has a white background, surrounded by a slightly darker border that stands out against the colored background of the element #wrapper.
We will start with a CSS rule for #content, adding the following code to our stylesheet:
#content {
background-color: white;
border: 1px solid #f0f0f0;
padding: 0;
}These rules should be fairly self-explanatory by now: we have given the element a white background and a border slightly darker than the background of #wrapper. We have also set the padding to 0. Since we defined ten pixels of padding for the element #wrapper, a ten-pixel-wide border in the background color of #wrapper appears around the element #content. This is exactly the effect we wanted to achieve based on the graphic design.
Next, we will add space between the element div with ID #content and the border. We could add margins to every individual element in this area. However, it is easier to create a new element div inside #content and give it the attribute class="inner". We can then define a 30-pixel margin for #content .inner to create this space.
#content .inner {
margin: 30px;
}Now we can turn to the contents of the element div with ID #content. First comes the World Cup ’06 image at the top of the content area. I placed it here in the document because I want to float it to the right using the property float.
To do this, add the style rules for the element #worldcuplogo to the stylesheet. The property float has the value right, and right and bottom margins are defined for the logo to provide space between it and the content flowing around it.
#worldcuplogo {
float: right;
margin: 0 0 20px 40px;
}Once we have added the attribute id="worldcuplogo" to the tag <img>, it appears on the right edge of the page with the remaining content flowing around it, as shown in the following figure.
Figure: The logo floats on the right.
Our layout is really taking shape now. After adding a few very simple CSS rules, a few elements div and an identifier, we are already very close to our initial design. What I like about developing layouts with CSS is how quickly simple pages can become attractive. If necessary, you can create a news page or a simple announcement layout like this one in a very short time.
The heading “Announcement” is an element h1. We can target it with a selector that applies to all elements h1 inside an element div with ID #content.
#content h1 {
font-size: 120%;
color: #01407a;
padding: 0.3em 0 0.3em 30px;
background-image: url(img/ball.gif);
background-repeat: no-repeat;
background-position: left center;
border-top: 1px solid #c5d6e2;
border-bottom: 1px solid #c5d6e2;
}We have given this element the ball image as a background, shown to the left of the heading in our design. We only want the image to appear once, so we set the property background-repeat to no-repeat. We also use the property background-position to move the image to the left and center it vertically.
To stop the heading overlapping the image, we give it 30 pixels of left padding. Top and bottom padding adds space between the heading and the border lines. The following figure shows the current layout.
Figure: The heading with its background image.
Now we can work on the heading h2 below the header. Our design specifies that this second-level heading should use a larger font than the heading h1. The properties we need to define for the rule #content h2 are quite straightforward.
#content h2 {
font-size: 260%;
font-weight: normal;
font-family: Georgia, Times, "Times New Roman", serif;
color: #032469;
border-bottom: 1px solid #c5d6e2;
margin: 1em 0 0 0;
}Here we have chosen a serif font for the second-level heading to match the design. The remaining text above the tournament schedule is marked up as paragraphs in the HTML. In these paragraphs I first want to increase line spacing a little. We can do this with the property line-height.
#content p {
line-height: 1.6em;
}The text directly below the headings h2 gives the date of the article concerned. For this, we add to this line’s opening tag <p> the attribute id="dateline" and create the following rule for that attribute:
#dateline {
font-size: 160%;
font-weight: normal;
font-family: Georgia, Times, "Times New Roman", serif;
color: #032469;
margin: 0.3em 0 0 0;
}The next paragraph is bold in our design. We therefore give its opening tag <p> the attribute class="intro" and write the following rule for this class in our stylesheet:
.intro {
font-weight: bold;
}Excellent! All the page content is now formatted apart from the tournament schedule table. We will tackle the table next, but first let us take a moment to enjoy the fruits of our work. View the results so far in the browser: they should look like the next figure.
Figure: All content except the table is formatted.
Copyright © 2006 of the German translation, dpunkt.verlag GmbH
You may print the online version for your private use.
Otherwise, this chapter from “CSS − Anspruchsvolle Websites mit Cascading Stylesheets” 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.
dpunkt.verlag GmbH, Ringstraße 19, 69115 Heidelberg
back to top