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 CSS
−based Layout
</
title> 6 <style type=”text/css”
> 7 div.slotA
{ 8 position: relative;
9 background: red;
10 } 11 div.slotA1
{ 12 position: relative;
13 height: 200px;
14 overflow: auto;
15 background: green;
16 } 17 div.slotA1
> div.slotB
{ 18 position: absolute;
19 width: 20%;
20 background: yellow;
21 } 22 div.slotA1
> div.slotC
{ 23 position: absolute;
24 left: 20%;
25 width: 80%;
26 background: gray;
27 } 28 div.slotD
{ 29 position: relative;
30 background: purple;
31 } 32 </
style> 33 </
head> 34 <body> 35 <div class=slotA
> 36 Red stuff represents slot A. Slot A is the title portion of a document.
37 It spans 100% of the width, and is as high as it needs to be.
38 </
div> 39 <div class=slotA1
> 40 <p>What is this green stuff? This is slot A1. Slot A1 includes
41 slot B and slot C.
42 However, this portion does not belong to either one. Slot A1 includes
43 both the main content and a left bar for navigation links.
</
p> 44 45 <p>Note that we have to set a height for this slot because it contains
46 slot B and slot C, which are block that have absolute positions.
</
p> 47 48 <p>The entire slot A1 (including slot B and slot C) share the height
49 of the slot A1. If the content is taller, then a scroll bar is usually
50 rendered to scroll through this block.
</
p> 51 <div class=slotB
> 52 <p>˜Slot B is colored yellow. Its width is 20% of the containing
53 block ”SlotA1”.
54 This portion is normally used to include navigation links.
</
p> 55 </
div> 56 <div class=slotC
> 57 <p>Slot C is colored gray. This is usually where the main content goes.
58 Its
59 position uses slot A1 as the frame of reference. We need to specify
60 the left to be 20% because that part is used by the slot B.
61 The width of the slot is 80% because 20% of the full width of
62 slot A1 is already used for slot B.
</
p> 63 </
div> 64 </
div> 65 <div class=slotD
> 66 This is slot D (purple). This slot is usually reserved for copyright
67 notice and a email link to the webmaster.
68 </
div> 69 <body> 70</
html>
Ah, this is much better. You can try to resize the browser, and visualize how the various blocks will be
resized.