One problem you are sure to have is removing unwanted vertical space. Tips to try include:
Unless you include each piece of text in a separate table cell there is no way to control the space between each line of text. You can either have no space between lines using <br> or have a whole line of space using <p>. Wrong! There is a way to control the height of the vertical space between lines to exact pixel values using a transparent 1x1 pixel image.
|
Green Office Events Local Groups Contacts Join Us |
Standard HTML Here there is a <br> between each item in the menu, except there is a <p> between Join Us and Donate. You are restricted to only these 2 heights of spaces between items. This code uses 931 bytes. |
||||||||||
|
Green Office |
Spacer image trick If you want a spacing that is between these 2, then you need to use transparent spacer images. Here the height of the spacer image is varies from 2 to 14 pixels, but it can be whatever you want. <img src="images/blank.gif" height=5 alt=""> This code uses 1321 bytes (the size could be reduced by making the name of the images dir and the blank image shorter). |
||||||||||
|
HTML table spacing For comparison here is the way of controlling height using a table. Here all the spaces must be exactly the same since they are controlled by the cellpadding and cellspacing of the table. Note that this also adds the same amount of horizontal space which the blank image trick doesn't. This code uses 1301 bytes. |
Also, a way of exactly controlling horizontal space is to use the same single pixel transparent gif. Either adjust the height and width of the image, or adjust the amount of hspace or vspace. This allows you to position the elements on your page where you want them.
| |
Here, we have |
|
| <img src="images/blank.gif"
width=20 hspace=10 alt=""> |
<img src="images/blank.gif" width=45 alt=""> |
|
|
A normal paragraph.
A normal paragraph. |
||
|
<img src="images/blank.gif" height=45 hspace=10 align=left alt=""> |
|
Examples of sites that use this are:
Actually the best way of controlling white space is to use CSS.
|
A normal paragraph. This paragraph uses the text-indent property to create the indent at the beginning. Note that it only works with a correct <p> paragraph </p> A normal paragraph. |
A normal paragraph. This paragraph uses the margin-left property to create a hanging paragraph. Note that it only works with a correct <p> paragraph </p> A normal paragraph. |
|
|
<style type="text/css"> <p class="indent">Text</p> |
<style type="text/css"> <p class="hanging">Text</p> |
The single-pixel transparent gif can also be used to make sure that table columns (e.g. for margins or gutters) stay the correct width. You can specify the width of a table cell, but if there is a lot of content in the other cells, some browsers may squash the margin or gutter. Putting a single pixel gif in the table cell means that it can never be less wide than the image.
A single-pixel gif can also be used to make blocks of colour - here the trick is to make a set of single-pixel gifs in different colours, and then to adjust the image using the height and width attributes of the <img> tag.
|
e.g. <img src="images/red.gif" width="80"
height="23" hspace="5"> The single pixel GIFs range from only 35 to 48 bytes. |
||
|
Your single pixel GIF can even be an animated GIF. The animated single pixel GIFs range from only 111 to 135 bytes.
|
||
|
Can also get lines and blocks of colour with table background colours and CSS. Animations are not possible with these however. |
The <hr> tag does allow the attribute color, but this is an IE only tag. To get colourful lines in both browsers you need to use a coloured single-pixel gif. The <hr> tag also has default spacing above and below the line. You can control this more exactly if you use a coloured single-pixel gif instead of an <hr>
| A piece of text above the line
A piece of text below the line |
This example uses the normal <hr> tag with size set to 1 and a color attribute. <hr size=1 color="#993300"> |
|
| A piece of text above the line A piece of text below the line |
This example uses the underline tag on the top line of text. <u>text</u> |
|
| A piece of text above the line A piece of text below the line |
This example uses a single-pixel gif with width set to 200 and a vspace of 1. This offers much more control over vertical spacing. <img src="images/black.gif" width=200 height=1 vspace=1 alt=""> |
The <form> tag is a block level element (like <div>, <h1>, <p>) and so it always has a blank line underneath it. But what if you don't want a blank line after your form?
Consider these two search boxes. They are completely identical except for the position of the <form> and </form> tags.
| Here is some text straight before the form
Here is some text straight after the form
|
This example uses correct HTML. First the <form> tag is opened and then the <table> tag. At the end the </table> tag is closed and then the </form> tag. This validates as correct HTML but it has an annoying blank line underneath. | |
| Here is some text straight before the form
|
This example uses bad HTML but there is no space after the form. The <form> tag is between the <table> tag and the <tr> tag. At the end the </form> tag is before the </table> not after it. This doesn't validate as correct HTML. |
Examples of sites that use this bad-HTML fix are:
The default HTML table borders are pretty thick and ugly, and Netscape doesn't support the bordercolor attribute, so to get nice table borders in all browsers it is necessary to nest 2 tables. If you only care about modern browsers you can use CSS.
|
This toolbox just uses one table with the border=1 and the bordercolor attribute of the table tag. It produces a thick coloured border in IE, but with an ugly grey bevel in Netscape. This code uses 1539 bytes. |
||||
|
This toolbox just uses one table with the border=1 and the bordercolor and bordercolordark attributes of the table tag. It produces a thin coloured border (with holes) in IE, but with an ugly grey bevel in Netscape. This code uses 1565 bytes. |
||||
|
This toolbox just uses one table with the border=1 and the bordercolor and bordercolorlight attributes of the table tag. It produces a thin coloured border (with holes) in IE, but with an ugly grey bevel in Netscape. This code uses 1566 bytes. |
||||
|
This uses a table within a table. As you expect the outside table has the red colour and the inside table has a red top row and a white bottom row. This works in Netscape. One common trick that a lot of sites do is to make the width of each of the tables exactly the same!!! I don't know why. This one here, both tables are set to 130 pixels wide. This code uses 1820 bytes. |
||||
|
This also uses a table within a table. As you expect the outside table has the red colour and the inside table has a red top row and a white bottom row. This works in Netscape. This one here, the outer table is set to 130 pixels and the inner one to 128 pixels wide and it doesn't seem to make any difference. This code uses 1820 bytes. |
||||
|
It is also possible to produce borders with CSS. This example uses the border property applied to the table tag. This does not work with Netscape. It is not supported in Dreamweaver. |
It is more difficult to get an attractive border throughout a table, i.e. between the cells as well as around the outside.
|
Here is a normal table with borders turned on. This automatically borders between the cells, but the border is the ugly grey bevel. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Here is an interesting way of acheiving thin borders throughout a table. This is copied from the old nzoom.com site. This works in Netscape. This is acheived by having the content in a table with cellspacing=1 which allows the background colour to show through. The background colour is added with another table. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Using CSS to get a border throughout a table is a little more tricky. If you simply add the border property to the table and the cells you get ugly double borders. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
The trick to avoid ugly double borders is to only add the border to 2 of the four possible sides. In this example the border is added to the bottom and left side of every <td>. It is also necessary to add a border to the overall table as well - this also needs to be applied to only two sides, but it needs to be the opposite two sides. In this example the border is added to the top and right of the <table>. |