XML technologies / CSS / Advanced websites with CSS / A simple CSS layout / Creating the document
(Excerpt from “CSS − Advanced websites with Cascading Stylesheets” by Rachel Andrew & Dan Shafer)
With the main components chosen, start by creating a document in XHTML containing every text element in the layout graphic, correctly marked up as XHTML.
This may feel strange if you are used to visual tools such as Dreamweaver and focusing only on appearance. CSS layout separates structure from presentation, letting us build a solid document before styling it.
Start with a document meeting XHTML.strict. Since all presentation uses CSS, a Strict declaration DOCTYPE is appropriate. Transitional DOCTYPEs for XHTML and HTML 4.01 permit deprecated elements and attributes, mostly presentational. We use CSS for appearance, so do not need them.
Example: index.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Footbag Freaks</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
</body>
</html>Declaring the character set
We use the element meta with the attribute http-equiv="Content-Type" to declare the character set, letting browsers and W3C’s validator identify it. Without this, characters can be misinterpreted and appear as garbage.
All examples use the character set ISO-8859-1, the default in most common editors and tools such as Dreamweaver. With another encoding, such as Unicode, adjust the elements meta accordingly.
The header
Add the content, dividing the document into the identified areas by enclosing each in tags <div> and </div>. Give each <div> an attribute id naming the section, so CSS can address and style each area separately.
After the element <body>, add this HTML:
<div id="header">
<p>The Home of the Hack</p>
<ul>
<li><a href="">Contact Us</a></li>
<li><a href="">About Us</a></li>
<li><a href="">Privacy Policy</a></li>
<li><a href="">Sitemap</a></li>
</ul>
</div> <!-- header -->Do not worry about images yet: CSS offers many insertion methods, and we will choose for each image while writing the stylesheet. The header therefore contains only “The Home of the Hack” and the main navigation links.
The main area
Next, wrap the main area in an element <div> with the attribute id set to content.
<div id="content">
<h2>Simon Says</h2>
<p>Simon Mackie tells us how a change of shoes has given him new moves and a new outlook as the new season approaches.</p>
<p><a href="">Read More</a></p>
<h2>Recent Features</h2>
<ul>
<li>
<h3>Head for the Hills: Is Altitude Training the Answer?</h3>
<p>Lachlan 'Super Toe' Donald</p>
<p>Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Praesent hendrerit iaculis arcu.</p>
<p><a href="">Full Story</a></p>
</li>
<li>
<h3>Hack up the Place: Freestylin' Super Tips</h3>
<p>Jules 'Pony King' Szemere</p>
<p>Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Praesent hendrerit iaculis arcu.</p>
<p><a href="">Full Story</a></p>
</li>
<li>
<h3>The Complete Black Hat Hacker's Survival Guide</h3>
<p>Mark 'Steel Tip' Harbottle</p>
<p>Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Praesent hendrerit iaculis arcu.</p>
<p><a href="">Full Story</a></p>
</li>
<li>
<h3>Five Tricks You Didn't Even Know You Knew</h3>
<p>Simon 'Mack Daddy' Mackie</p>
<p>Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Praesent hendrerit iaculis arcu.</p>
<p><a href="">Full Story</a></p>
</li>
</ul>
</div> <!-- content -->It will contain the large image and overlaid text highlighting a longer article, with four new entries below.
The sidebar
Finally, add the sidebar with a search form and important dates:
<div id="sidebar">
<h3>Site Search</h3>
<form method="post" action="" id="searchform">
<div>
<label for="keywords">Keywords</label>:
<input type="text" name="keywords" id="keywords" />
</div>
<div>
<input type="submit" name="btnSearch" id="btnSearch" />
</div>
</form>
<h3>Coming Events</h3>
<ul>
<li>10 Apr 06 -<br /><a href="">Seattle Zone Qualifier</a></li>
<li>13 Apr 06 -<br /><a href="">World Cup - Round 8</a></li>
<li>21 Apr 06 -<br /><a href="">FootbagOOM 05 - NY</a></li>
<li>28 Apr 06 -<br /><a href="">WFPA AGM - Hong Kong</a></li>
<li>3 May 06 -<br /><a href="">World Cup - Round 9</a></li>
</ul>
<h3>Move of the Month</h3>
<h4>The Outer Stall</h4>
<p>Eti bibendum mauris nec nulla. Nullam cursus ullamcorper quam. Sed cursus vestibulum leo.</p>
<p><a href="">more</a></p>
</div> <!-- sidebar -->The markup is complete. Save and view the page in a browser using its default element styles, as shown below. It is not pretty, but readable!
Figure: The text-only page.
Before adding CSS to reproduce the design, validate the page. Checking now gives us a valid foundation, avoiding problems caused by faulty markup.
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