3.3.1 Begin with organization

Let’s begin with just the organization of the document. This is illustrated in listing 2.


Listing 2:Organization
 
1<!DOCTYPE HTML PUBLIC ”//W3C/DTD_HTML_4.01//EN” 
 
2
  ”http://www.w3.org/TR/html4/strict.dtd”> 
3<html lang=”en”> 
4  <head> 
5    <title>An illustration of CSSbased Layout</title> 
6    <style type=”text/css”> 
7      div.slotA {  
8        background: red; 
9      } 
10      div.slotA1 { 
11        background: green; 
12      } 
13      div.slotA1 > div.slotB {  
14        background: yellow; 
15      } 
16      div.slotA1 > div.slotC { 
17        background: gray; 
18      } 
19      div.slotD { 
20        background: purple; 
21      } 
22    </style> 
23  </head> 
24  <body> 
25    <div class=slotA>  
26      <p>Red stuff represents slot A. Slot A is the title portion of a document. 
27      It spans 100% of the width, and is as high as it needs to be.</p> 
28    </div> 
29    <div class=slotA1> 
30      <p>What is this green stuff? This is slot A1. Slot A1 includes 
31      slot B and slot C. 
32      However, this portion does not belong to either one. Slot A1 includes 
33      both the main content and a left bar for navigation links.</p> 
34 
35      <p>Note that we have to set a height for this slot because it contains 
36      slot B and slot C, which are block that have absolute positions.</p> 
37 
38      <p>The entire slot A1 (including slot B and slot C) share the height 
39      of the slot A1. If the content is taller, then a scroll bar is usually 
40      rendered to scroll through this block.</p> 
41      <div class=slotB> 
42        <p>˜Slot B is colored yellow. Its width is 20% of the containing 
43        block ”SlotA1”. 
44        This portion is normally used to include navigation links.</p> 
45      </div> 
46      <div class=slotC> 
47        <p>Slot C is colored gray. This is usually where the main content goes. 
48        Its 
49        position uses slot A1 as the frame of reference. We need to specify 
50        the left to be 20% because that part is used by the slot B. 
51        The width of the slot is 80% because 20% of the full width of 
52        slot A1 is already used for slot B.</p> 
53      </div> 
54    </div> 
55    <div class=slotD> 
56      <p>This is slot D (purple). This slot is usually reserved for copyright 
57      notice and a email link to the webmaster.</p> 
58    </div> 
59  <body> 
60</html>

In this code, we have the major blocks set up by <div> tags. The CSS styles only define the background colors for each division. It is rendered as in figure 1.


PIC

Figure 1: The rendering of the code in listing 2.


Even in this simple example, there are a few important concepts.

For a more in depth discussion of selectors, please refer to http://www.w3.org/TR/1998/REC-CSS2-19980512/selector.html.