Web Design |
nesting tables |
||||||||
main menushelp pagesprinter-friendly/text-only version |
Something that occasionally confuses those who are new to the technique is the nesting of tables inside each other. In other words, a table cell (<td> tag) that itself contains a table. This is no more complicated than any other example of nesting, such as links within paragraphs, or the whole page content within the <body> tag, but I think what makes it hard for some people to grasp is the need to keep a very close eye on your table structures, and ensuring you have closed all tags in the correct order. Why might you want to nest tables? Well, at a simple level, it can help you achieve effects like this. The HTML used to get this effect follows beneath:
<table summary="Some Emperors of Rome" style="width: 75%;"> Hopefully the indentations here make the structure clear. It really is just a matter of keeping track of your opening and closing tags. Note that the attributes applied to the first "parent" table don't apply to the "child" table within it. So there's no padding between the cells of the "child", for instance. More obviously, the same applies the other way, so there is no border round the "parent". You can also do this kind of thing with rowspan and colspan attributes: in this case this would be a 4-row table with the first cell on the first row including rowspan="4". Each of the other three rows would have only the second tag in it ("Tiberius", etc.). However, any more complex than this and nesting is a lot easier. This particularly applies when you remember that this whole page is in fact laid out using a table and the "child" table is in fact a "grandchild". Here is a link to the page with more information about using tables to lay out whole pages. |
Material on this site is © Drew Whitworth, 2005 Permission will usually be given to reproduce material from this site for non-commercial purposes, if credit is given. For enquiries, e-mail Drew at andrew [dot] whitworth [at] manchester [dot] ac [dot] uk.