HTML
HTML introduction
HTML basics
HTML colors
HTML backgrounds
HTML text
HTML font
HTML text formatting
HTML entities
Display tags
HTML links
Email links
Types of links
HTML images
HTML image maps
HTML tables
HTML frames
HTML forms
Fieldset/legend tags
HTML stylesheets
Div/span tags
HTML layout
HTML marquees
HTML multimedia
HTML meta tags
HTML document types
HTML base tag
HTML scripts
URL formatting
Encoding and decoding
HTML summary

Programming

Programming intro
Java

Markup

First webpage guide
XHTML

Style & Layout

CSS

Browser scripting

Javascript
VBScript
AJAX

Server scripting

PHP
ASP

Making money online

Make money online

HTML layout

There are several ways you can present the content on a webpage. However, not many options exist in HTML using just the <body> tag. You can specify a layout for pages using tables or CSS.

This lesson focuses on:

Using tables for layout

You can use various table properties such as the tables width, height, and border to layout the content on a page as well as the properties of table rows and cells.

Layout 1:

<table border="0" cellspacing="0" cellpadding="0" id="main">

<tr height="40">
<td colspan="2" bgcolor="white">
<!--first inner table begins here-->
<table border="0" title="top" id="top">
<tr>
<td>
Site logo and catch phrase
</td>
</tr>
</table>
<!--first inner table ends here-->
</td>
</tr>

<tr height="250">
<td>
<!--second inner table begins here-->
<table border="0" id="nav" title="Navigation">
<tr><td>Site menu here</td></tr>
<tr><td>Site menu here</td></tr>
<tr><td>Site menu here</td></tr>
</table>
<!--second inner table ends here-->
</td>

<td>
<!--third inner table begins here-->
<table border="0" id="content" title="content">
<tr><td>Content goes here</td></tr>
</table>
<!--third inner table ends here-->
</td>
</tr>
</table>

Output:

You can remove the border from the table to make it appear as if the different parts of the page are integrated together, but still keep them distinct by displaying them with different background colors as in this next layout.

Layout 2:

<table id="main" title="main" border="0" width="100%">
<tr height="50">
<td bgcolor="lightcyan">
<!--first inner table begins here-->
<table id="top" title="top">
<tr><td>Site logo and catch phrase</td></tr>
</table>
<!--first inner table ends here-->
</td>
</tr>
<tr height="30">
<td bgcolor="#E5E5E5">
<!--second inner table begins here-->
<table id="navigation" title="navigation">
<tr>
<td>Site menu here</td>
<td>Site menu here</td>
<td>Site menu here</td>
</tr>
</table>
<!--second inner table ends here-->
</td>
</tr>
<tr>
<td>
<!--third inner table begins here-->
<table id="content" title="content" height="300">
<tr><td>Content goes here</td></tr>
</table>
<!--third inner table ends here-->
</td>
</tr>
</table>

Output:



Using CSS for layout

The newer way to specify a pages layout is CSS. Using CSS as opposed to tables gives you more flexibility over your layout and is less confusing (all those inner tables you avoid by using CSS instead of tables!)

Two column layout with CSS:

<div id="top">Site logo and catch phrase</div>

<div id="leftSide">Site menu here<br /><Site menu here<br />Site menu here<br /></div>

<div id="rightSide">Content</div>

The CSS that creates this layout:

#top{

width: 200px;
background-color: #E5E5E5;
margin-bottom: 20px;

}

#leftSide{

float:left;
margin-top: 10px;
padding-right: 10px;
height: 200px;
border-right: dashed gray 1px;

}

#rightSide{

color: rgb(37,66,95);
font-weight: bold;
text-align:center;

}

Output:

Practice

Online code editor
Practical examples
Practical exercises
Step-by-step tutorials

Reference

Terms glossary
Reference material

Rate this site

Rate this site
Visitor comments