In order to appreciate and create various types of layouts effectively, you need a firm understanding of positioning, floating, clearing, padding and margin. (See CSS Training Manual)
There are several ways to create CSS Layouts (absolute positioning, negative margin, and floating). Floating is a popular technique; however, because floated elements are taken out of the normal flow of the document like Absolute Positioning (AP) elements, they are not easily "seen" by other elements. To resolve this dilemma, they have to be cleared throughout the layout. It is best practice to float most elements and clear only once usually in the footer since a single float can clear all of the columns ABOVE it. It is important to remember to set the width of any floated div.
All of the layouts that we will discuss will increase their vertical height auomatically based on the content within them. You could however specify a height to limit the vertical size and add a scroll bar to a container to accomodate text content that is larger than container. However, the horizonal width should always be set using various types of measurements (pixels, percentages, or ems)
You can use Dreamweaver to create various layouts ranging from 1-3 columns (with or without header and footer) and in a variety of layout styles (i.e., fixed, liquid, elastic, hybrid (elastic/liquid) and absolute). What some developers/designers may not know is the advantages and disadvantages of the various types:
FIXED – The overall width and any internal columns are specified in PIXELS which allows the layout to be centered in user’s browser window. The columns do not resize based on browser size or the site user’s text settings.
Pros: It is the most common of all fixed layouts; give designer/developer more control over layout and positioning. The size is always fixed (e.g., 960px).
Cons: The size is always the same size regardless of monitor's size or resolution—Hence, on a high screen resolution (1440x900), an 800x600 layout will appear tiny in the center of the screen. Conversely, on a low screen resolution (800x600), a 1024x768 layout will cause horizontal scroling bars to appear.
LIQUID – The overall container width and any internal columns are specified in PERCENTAGES which is calculated from the current size of user’s browser window. The page changes if the site user makes the browser window smaller or larger, but does not change based on the user’s text settings.
Pros: The layout will SCALE in relation to the browser window—If the browser window gets bigger, the columns get wider. Conversely, if the browser window gets smaller, the columns get narrower; they make effective use of space.
Cons: At a small window size, line lengths can be difficult to read especially in multi-column layouts. However, adding a min-width property in pixels or ems can be used to prevent the layout from becoming to small. Conversely, if the window is too large, line length becomes to long and more difficutly to read as well. To prevent this from happening, you can constrain the container div to a percentage (e.g., 85%) or set the padding and margin as percentage as well to that they will increase in width in relaion to the browser window size preventing the columns from getting to wide. You can set the max-width property in pixels to prevent the content from getting excessively wide on large monitors.
ELASTIC – The overall width and any internal columns are specified in EMS relative to the font size instead of the browser width which allows the layout to scale with the browser’s designated base font size.
Pros: By setting the widths in ems, the font size will increase as the entire layout scales which help keeps the line length to a readable size—all of the HTML elements will stay in the same place relative to one another. However, they just increase in size.
Cons: Because the entire layout increases when the text size is increased, the layout can become larger and cause horizontal scroll bars to appear. To prevent this from happening on standards compliant browsers, you could add a max-width of 100% to the body tag.
ELASTIC-LIQUID HYBRID – [Best of both worlds] Columns are a combination of the elastic and liquid layout. The overall page width is 100% but the side column(s) values are in ems. For example, in a two-column hybrid, the main liquid column scales based on the browser size and the elastic column scales based on the size of the user’s text settings.
Pros: The elastic-liquid layout never scales larger than the browser window.
Cons: The prblem with elastic-liquid hybrid is not with text or columns, but with images—If the width of the layout is reduced, fixed-width imagees will shift and may interact wih other images. Conversely, Increasing the width of the layout can create unwanted gaps. However, there are several solutions to resolve these problems. SEE PAGE 147-148.
ABSOLUTE POSITIONED – all the other layouts use floats for columns, the absolutely positioned layout use AP elements (formerly calledd layers) for columns.
Pros: Easy to create using absolute position (AP) elements.
Cons: Don't work well in all browsers.
The reason you want to create layouts with columns is because long lines are more difficult to read. (SHOW ONE COLUMN vs. TWO COLUMNS)
<body> <div id="header"> <h1>Header goes here...</h1> </div> <div id="main_content"> <p>Main Content goes here...</p> </div> <div id="menu"> <p>Menu goes here...</p> </div> <div id="footer"> <p>Footer goes here...</p> </div> </body>
<style>
/*Styling containers =================*/
#header {width:960px; height:100px;background:#999}
#main_content {width:740px;}
#menu {width:200px; background:#DDD;}
#footer {width:960px; height:40px; background:#DDD;}
</style> </head>
#main_content {width:740px;float:right;} #menu {width:200px; background:#DDD; float:left;}
#footer {width:960px; height:40px; background:#DDD; clear:both;}
<body> <div id="container"> <div id="header"> <h1>Header goes here...</h1> </div> <div id="main_content"> <p>Main Content goes here...</p> </div> <div id="menu"> <p>Menu goes here...</p> </div> <div id="footer"> <p>Footer goes here...</p> </div> </div> </body>
<style>
/*Styling containers =================*/
#container{width:960px; height:640px; border:1px solid black;}
h1, p, div{padding:0; margin:0;}
#header {width:960px; height:100px; background:#999}
#main_content {width:740px;float:right; height:500px;}
#menu {width:200px; background:#DDD; float:left; height:500px;}
#footer {width:960px; height:40px; background:#DDD; clear:both;}
</style>
#container{width:960px; height:640px; border:1px solid black; margin: 0 auto;}
NOTES:
You may have noticed that the text in the header, sidebar and footer is hugging the left-edge of their respective containers. To avoid IE 5.x proprietary box model and to resolve this problem will we write some rules to add HORIZONTAL padding NOT to the CONTAINERS but to the CONTENT of the containers using descendant selectors.
Converting a two column fixed-width centered layout to a three-column layout is similar to a two column but with a few modifications and adding some additional containers.
<div id="main_content"> <p>Main Content goes here...</p> </div> <div id="secondary_content"> <p>Secondary Content goes here...</p> </div>
<div id="contents"> <div id="main_content"> <p>Main Content goes here...</p> </div> <div id="secondary_content"> <p>Secondary Content goes here...</p> </div> </div>
/*Styling containers =================*/
#container{width:960px;height:640px; border:1px solid black; margin: 0 auto;}
#header {width:960px; height:100px;background:#999}
#main_content {width:420px;float:left; height:500px;}
#secondary_content {width:320px;float:right; height:500px;background:#6B6B6B;}
#contents {width:740px; float:right;}
#menu {width:200px; background:#DDD;float:left; height:500px;}
#footer {width:960px; height:40px; background:#DDD; clear:both;}
h1, p, div {padding:0; margin:0;}
/*Styling text in containers ============*/
#header h1, #menu p, #footer p {margin-left:20px;}
</style>
Creating a liquid layout is the next easiest layout to create after creating a fixed-width layout. In fact, you can easily convert a two-colomn fixed layout to a three-column liquid layout by converting f the width measurements from pixels to percentages:
<style>
/*Styling containers =================*/
#container{width:85%;height:640px; border:1px solid black; margin: 0 auto;}
#header {width:100%; height:100px;background:#999}
#main_content {width:66%;float:left; height:500px;}
#secondary_content {width:31%;float:right; height:500px;background:#6B6B6B;}
#contents{width:75%; float:right;}
#menu {width:23%; background:#DDD;float:left; height:500px;}
#footer {width:100%; height:40px; background:#DDD; clear:both;}
h1, p, div {padding:0; margin:0;}
/*Styling text in containers ============*/
#header h1, #menu p, #footer p {margin-left:20px;}
</style>
NOTES:
Initially, the elastic layout looks similar to the fixed-width layout at the default text sizes. However, once you start to scale it, the text will resize accordingly.
Converting a three-column liquid to a three-column elastic layout is a matter of changing the width measurements from percentages to EMS. The key is to set a base font-size as a PERCENTAGE and then set the widths to EMS. Since the base font size on most browsers is 16 pixels. The goal is to set the font size so that 1 em is equivalent to 10 pixels—This turns out to be about 62.5%.
<style>
/*Styling containers =================*/
body{font-size:85.2%;}
#container{width:96em; height:640px; border:1px solid black; margin: 0 auto;}
#header {height:100px;background:#999}
#main_content {width:54em; float:left; height:500px;}
#secondary_content {width:20em; float:right; height:500px;background:#6B6B6B;}
#contents{width:74em; float:right;}
#menu {width:20em; background:#DDD; float:left; height:500px;}
#footer {height:40px; background:#DDD; clear:both;}
h1, p, div {padding:0; margin:0;}
/*Styling text in containers ============*/
#header h1, #menu p, #footer p {margin-left:20px;}
</style>
To convert a three-column elastic layout ot a three-column elastic-liquid hybrid layout
<style>
/*Styling containers =================*/
body{font-size:85.2%;}
#container{width:96em; max-width:100%; height:640px; border:1px solid black; margin: 0 auto;}
#header {height:100px; background:#999}
#main_content {width:54em; max-width:66%; float:left; height:500px;}
#secondary_content {width:20em; float:right; height:500px;background:#6B6B6B;}
#contents{width:74em; max-width:75%; float:right;}
#menu {width:20em; max-width:23%; background:#DDD; float:left; height:500px;}
#footer {height:40px; background:#DDD; clear:both;}
h1, p, div {padding:0; margin:0;}
/*Styling text in containers ============*/
#header h1, #menu p, #footer p {margin-left:20px;}
</style>