In this tutorial you will learn how to 'nest' tables and format cells using html for use in your web design.
Nesting? what's that? Basically its putting tables inside other tables,
you remember in the basic tables tutorial i said you can put other
tables inside table cells - well here's how.
Hi, I'm in a nested table... but its a but boring!
As you can see, the T able D ata is, in this case, a whole new table, albeit with only one cell in each.
What's the point in nesting tables - making your job easier, for example consider the following:
The page is very neatly laid out, and more
importantly, you can safely edit the links table and the content table
without damaging the overall layout, you might also choose to put the
header in a table, for example if you wanted to put more links
horizontally under the header. The code for the above table is:
| <table width="300" height="203" border="1" cellpadding="0" cellspacing="0" bordercolor="#990000">
<td height="30" colspan="2">HEADER IMAGE</td>
<td width="114" height="159" align="center" valign="middle">NAV IMAGE<br>
<table width="100" border="1" cellpadding="0" cellspacing="0" bordercolor="#006600">
<td width="180" align="center">
<table width="95%" height="159" border="1" cellpadding="0" cellspacing="0" bordercolor="#000066">
<td align="center">PAGE CONTENT</td>
<td height="10">Copyright Information</td>
This may look a bit confusing, but its all quite simple - the same
three tags repeated in the correct order. I have colored the code
according to which table it represents, as shown in the diagram, you
can ignore the extra attributes for now (bordercolor="#blah",
align="blah", border="1" etc.) - they were simply used to show which
tables were nested.
Basically you just have to make sure that you don't overlap tags, i.e.
<font size="6"><b>Hello World!</b></font> -- is correct
<b><font size="6">Hello World!</b></font> -- is incorrect
The same rules apply for tables, and most errors occur when you don't
close tags, to prevent this (it WILL happen, believe me!) you can
either use a WYSIWYG (what you see is what you get) editor, such as Macromedia Dreamweaver
my personal favorite - these will generate the code for you, all in the
right order. If you can't afford the hefty price tag of these programs,
then you can get your code validated here
, simply enter the URL of your page and it checks to see it complies with the W3C
Those tables were all well and good... but they were a bit boring yes?
To make them more exciting there are a few tags you should be aware of.
To make your tables have no borders, simply add the border="0"
attribute to your table tag, i.e. <table border="0"> obviously
you can also make your table borders bigger - experiment! its the best
way to learn!
Changing the background color of a cell
Another major formatting attribute is the bgcolor attribute, this can
be defined using simple, word-based colors, or hexadecimal values, for
the purpose of this tutorial i will use both.
To dictate the background color of a cell you insert the bgcolor attribute into your <td> tag, for example:
<td bgcolor="red"> -- simple word-based colors
<td bgcolor="#ff0000"> -- hexadecimal color values
both of the above will generate this:
if we then add the border="1" attribute,
we get this:
now, for my last trick in this tutorial, the bordercolor attribute
As you can see there are many possibilities (especially with millions of possible color values)
the code to generate the above table (complete with bordercolor , border and bgcolor attributes) is shown below:
| <table width="100" border="1" cellpadding="0" cellspacing="0" bordercolor="#000000">
<td bgcolor="#FF0000"> </td>
I hope this came in useful!