Articles

How to construct tables in HTML - APSense help.

by Bj aka Bill Brown Hosting and Backup Service provider
How to construct tables in HTML - APSEnse help.


Tables can be used to create a great diversity of layout in your posts.
The examples and the code I have given are a demonstration of the various things you can do with tables and if you copy the code to a notepad document and save as tables.html to your desk top you will be able to open it in your browser.
Then by right clicking and selecting view source you will be able to change things and experiment.
Remember you must click on save when you have made changes the hit the refresh to see what effect it had.
Keep a spare copy of the original coding in case you cant correct something if it goes wrong.

This is a demonstration to show how tables can be used to manipulate the layout of both your blogs and group posts.
This area is where the title can go. It is center aligned and spans 3 columns.
This is the first of three elements on this row. It is 25% of the total table width and is left aligned this is the second element on this row.
It is center aligned and is 50% of the total table width.
This is the third element of this row and is 25% of the total table width and is right aligned
On this row I have created two elements. this one spans the first two columns and is therefore 75% of the total table width. (the 25 % column 1 uses and the 50% column 2 uses) This is another right aligned element using the remaining 25% of the total table width.
This is a right aligned element that is less in height than the center element. This element although created in the 4th row also extends down into row 5

I have also added extra text here in this element
To demonstrate the next row
Note how the vertical alignment of the text is center aligned in the two red elements in the 4th row


This is the third element of table row 4
Row 5 Text bottom vertically aligned row 5 Text top vertically aligned
Points to note.

All elements will automatically adjust their height to display the content that you enter in them.
The content can be text, banners, images, or any combination of these 3 items.
The center element spanning rows 4 and 5 will adjust to stay the same height as the combined height needed by the left and right elements of rows 4 and 5 should it be greater than needed by the content of the center element.
The side elements will adjust in height to ensure that their combined height is equal to the height of the center element if it needs more height than the two side elements of rows 4 and 5 combined.


This is the same as above but with the table borders showing so that you can see the areas being used and the spacing between each area.

This is a demonstration to show how tables can be used to manipulate the layout of both your blogs and group posts.
This area is where the title can go. It is center aligned and spans 3 columns.
This is the first of three elements on this row. It is 25% of the total table width and is left aligned this is the second element on this row.
It is center aligned and is 50% of the total table width.
This is the third element of this row and is 25% of the total table width and is right aligned
On this row I have created two elements. this one spans the first two columns and is therefore 75% of the total table width. (the 25 % column 1 uses and the 50% column 2 uses) This is another right aligned element using the remaining 25% of the total table width.
This is a right aligned element that is less in height than the center element. This element although created in the 4th row also extends down into row 5

I have also added extra text here in this element
To demonstrate the next row
Note how the vertical alignment of the text is center aligned in the two red elements in the 4th row


This is the third element of table row 4
Row 5 Text bottom vertically aligned Row 5 Text top vertically aligned
Points to note.
All elements will automatically adjust their height to display the content that you enter in there.
The content can be text, banners, images, or any combination of these 3 items.
The center element spanning rows 4 and 5 will adjust to stay the same height as the combined height needed by the left and right elements of rows 4 and 5 should it be greater than needed by the content of the center element.
The side elements will adjust in height to ensure that their combined height is equal to the height of the center element if it needs more height than the two side elements of rows 4 and 5 combined.



You can copy the coding below into a note pad document and play with it.

One important thing to note is I always make table widths dynamic in that I do not use any fixed widths I always work with percentages of the total width.
This will make the table elements expand and contract (to a certain point) if the viewer changes the width of their browser and it will keep everything in proportion as far as width goes. Naturally if you have an image or banner in one of the elements then they will only close up to the width of the image or banner. before the scroll bar activates.
This is a personal preference of mine you can however make something a fixed width by replacing the percentages in the width command by a set number of pixels. If you do this then the total should not be more than 750 to 800 or it will be too wide for those viewing on a 800 wide screen resolution. You will also need to calculate the number of pixels you need for each element in each table row.
for using in posts in APSense I strongly recommend using the percentage method as there is only about 500 pixel width available.


Basic elements of a table.

A table consists of 1 or more rows (TR) and a row consists of one or more elements or cells (TD).
All three parts MUST be included and for each open command there must be a close command.
The Commands MUST be nested in side each other as follows

<table> The open table command
<tr> The open table row command
<td> The open row element command
the content of the element goes here.
</td>The close row element command.
</tr> The close Row command.
</table> The close table command.


As you will see in the coding below for each row opened there must be at least one Row element and the row must be closed before opening the next row.

WARNING: All the table components MUST be used. The aim of this post is To help members add some diversity to their posts. It is not intended to add extra work to supports already heavy workload by them having to go round deleting post that we cant delete because we forgot to close the table off for example.


Commands used in the table definition

<table width="100%" cellpadding="3" cellspacing="5" border="0" bordercolor="#FF0000" bgcolor="#FFFFD9">

width
Tells the table how much available width to use in this case all available. The 100% could be changed to a set number of pixels as described in the above notes.

cellpadding
tells the table how much space in pixels you want between the content and the edge of the Row element (cell) This can be 0 to what ever you want but I personally rarely use more than 5.

cellspacing
Tells the table how much space in pixels you want between cells. Note that your back ground color will be visible if you set this to 1 or more.

border
defines the pixel width of the border. if set to 0 then no border is shown as you see in the first example on this page. in the second example I changed the 0 to 2.

bordercolor
defines the color of the border to be shown if the border command is set to 1 or more. and is the Hexadecimal code for the color in this case Red.

bgcolor
This is again a hexadecimal code and defines the background color of the area of the page the table covers. In this case I have set it to a slightly off white color.


Commands used in table row definitions
Note these commands are optional and only needed if you want special formatting.

bgcolor
Where as the bgcolor in the table defines the background color of the complete table when used in a table row declaration the color takes precedence over the table bgcolor command for the row back ground color.


Commands used in row element definitions
Note: These commands are optional and only needed if you want special formatting.

align
defines how the text will be aligned horizontally in the element. The options are left, right, or center. If no align command is used then the default is left.

valign
defines how the text will be aligned vertically in the element. The options are top, bottom, or middle. If no valign command is used then the default is middle.

colspan
This is used to make an element spread across the top of columns we want it to. In this case as I have rows with 3 elements and in the first row I want the single element to act as a header so I have told it to span all 3.
In row 3 I wanted the first element to span the first and second columns so used 2.

rowspan
This is used to make an element extend vertically into more than one row. In this case as I have made the center ellement of row 4 extend down to row 5 as well so I used 2.



See Making the most of your APSense Business Center. 8. Basic HTML Tips and tricks. For an explanation of basic text formatting codes used inside the row elements.

The code


<table width="100%" cellpadding="3" cellspacing="5" border="0" bordercolor="#FF0000" bgcolor="#FFFFD9">
<tr>
<td align="center" colspan="3">
<font color="#FF0000"><b>
This is a demonstration to show how tables can be used to manipulate the layout of both your blogs and group posts.
<br />This area is where the title can go. It is center aligned and spans 3 columns.</b></font>
</td>
</tr>
<tr bgcolor="#00FFFF">
<td width="25%" align="left">
This is the first of three elements on this row. It is 25% of the total table width and is left aligned
</td>
<td width="50%" align="center">
this is the second element on this row.
<br />It is center aligned and is 50% of the total table width.
</td>
<td width="25%" align="right">
This is the third element of this row and is 25% of the total table width and is right aligned
</td>
</tr>
<tr bgcolor="#FFFF00">
<td width="75%" align="left" colspan="2">
On this row I have created two elements. this one spans the first two columns and is therefore 75% of the total table width. (the 25 % column 1 uses and the 50% column 2 uses)
</td>
<td width="25%" align="right">
This is another right aligned element using the remaining 25% of the total table width.
</td>
</tr>
<tr bgcolor="#FF0000">
<td width="25%" align="right">
<font color="#FFFFFF"><b>This is a right aligned element that is less in height than the center element.</b></font>
</td>
<td bgcolor="#FF00FF" width="50%" align="center" rowspan="2"><b>
This element although created in the 4th row also extends down into row 5
<br />
<br />I have also added extra text here in this element
<br /> To demonstrate the next row
<br />Note how the vertical alignment of the text is center aligned in the two red elements in the 4th row
<br />
<br />
<br />
</b>
</td>
<td width="25%" align="left">
<font color="#FFFFFF"><b>
This is the third element of table row 4
</b>
</font>
</td>
</tr>
<tr bgcolor="#00FF00">
<td width="25%" align="left" valign="bottom">
Row 5 Text bottom vertically aligned
</td>
<td width="25%" align="right" valign="top">
Row 5 Text top vertically aligned
</td>
</tr>
<tr bgcolor="#00FFFF">
<td align="left" colspan="3"><b>
Points to note.
<br />
<br />All elements will automatically adjust their height to display the content that you enter in them.
<br />The content can be text, banners, images, or any combination of these 3 items.
<br />The center element spanning rows 4 and 5 will adjust to stay the same height as the combined height needed by the left and right elements of rows 4 and 5 should it be greater than needed by the content of the center element.
<br />The side elements will adjust in height to ensure that their combined height is equal to the height of the center element if it needs more height than the two side elements of rows 4 and 5 combined.</b>
</td>
</tr>
</table>
<br />


Sponsor Ads


About Bj aka Bill Brown Magnate I     Hosting and Backup Service provider

2,648 connections, 57 recommendations, 7,767 honor points.
Joined APSense since, May 18th, 2007, From Leicester, United Kingdom.

Created on Dec 31st 1969 18:00. Viewed 0 times.

Comments

Jeff Greene Committed   Online Marketing Specialist/Consultant
Perfectly excellent information as always, Bill! TOPS to you! :)

The above layout can be astonishingly effective in displaying many types of media, giving a person a chance to create some really attractive and "sticky" elements on webpages...

I love playing around with multi-media art, so this layout will get a "workout" when I find the right elements! :)
Nov 1st 2007 11:27   
Bj aka Bill Brown Magnate I   Hosting and Backup Service provider
Hi Jeff,

this one took a bit of time to prepare to make sure it all came out right and that all the coding would show up where it was supposed to and not show where it wasnt lol



Nov 1st 2007 11:49   
Wendy Senior   
Wohooo

Talk about perfect timing

Was just trying to figure out I could get one of my charts here that I made (well edited it LOL)

Bang on Bill

Thanks heaps

Very useful information

While I am thinking about this Will it affect the whole page or just what you are working at the moment??

Wendy


Nov 1st 2007 14:33   
Bj aka Bill Brown Magnate I   Hosting and Backup Service provider
got your code wendy

will get back to you through message with it asap
but one thing I can see immediatly without converting it to readable code is you included header and body commands and that wont work.

Will confirm in an hour or so when i finished having some rest.


Nov 1st 2007 15:46   
Bj aka Bill Brown Magnate I   Hosting and Backup Service provider
Hi again Wendy

check your messages :-)

Nov 1st 2007 19:25   
Rusty Rose Advanced   
This is coding that I know and understand, Bill, and I happen to know that this was a lot of work on your part. I, for one, appreciate it. You did make clear the different heights to me. Now if I could just figure out how to color in the background of the table...... *Grin.

Thanks, Bill. It sure is nice having you in APSense. You're part of what makes this place so nice.
Nov 1st 2007 20:32   
Rusty Rose Advanced   
Sorry, I was so busy looking at the spacing, didn't realize it was already colored in. Will definitely make a copy of this html coding. Thanks again, Bill.
Nov 1st 2007 20:35   
Eric Smith Senior   Online Professional
Great Job Bj, I must admit i usually follow a cheat sheet when doing tables, but this example is super easy to follow... Thanks!!
Nov 1st 2007 20:35   
Bj aka Bill Brown Magnate I   Hosting and Backup Service provider
hi Eric,

each to their own, this was written out of my head, with no cheat sheets rofl


Nov 1st 2007 20:44   
Bj aka Bill Brown Magnate I   Hosting and Backup Service provider
Hi Rusty,

I spread it over 2 days to ensure it came out right
and tested it in an html page on my pc to see how it looked as I went.


Nov 1st 2007 20:56   
Eric Smith Senior   Online Professional
Hey Bj,

I basically tought myself html over a period of a couple of years... I used to view the source of other websites to see how they were put together. I concentrated on learning how to add images, hyperlinks and that sort of thing... I had a WYSIWYG editor at the time so i didn't bother learning tables.

It is something i will spend a lot of time on over the coming months...

Mind you, I have developed more than 100 Websites... Half of them were for other people...
Nov 2nd 2007 03:47   
Rocky Pacley Senior   
I know this will help a great deal I have to see if I can implement the right technique in order to keep the same look for a while, can css be implemented here?
Nov 2nd 2007 06:11   
Bj aka Bill Brown Magnate I   Hosting and Backup Service provider
Hi Rocky

I Have to admit I still have problems using css.

As far as I know yes, if you are verse in css.
Use the <script ...... /script> css type defeinition
as you would in the header of a page.
However dont use the head and body commands when formatting the blog.

We have to remember what we are effectivly doing is entering content into an already defined table (the blog post area) of an already defined page.
This is why I added the red warning. Mess it up and the complete page could be messed up to the point that the things that should show on the right hand side of our blog ( the delete, edit and so on ) could vanished as did happen to one unfortunate person.

If you know css try it and if it works message me I have an idea.


Nov 2nd 2007 06:43   
Indrit Shkodra Senior   
well i used css and it worked
Nov 2nd 2007 10:33   
Beth Schmillen Professional   
Thank you Thank you thank you! that is awesome what you've done with this coding.... something I can use and adjust for many purposes!

Beth
Nov 2nd 2007 10:45   
Eric Smith Senior   Online Professional
Bj / Rocky,

I'm with Bj on this still learning CSS...

I have recently discovered how to call a style sheet from an external server and i'm assuming that would be required for implementing CSS in this environment ?
Nov 2nd 2007 15:38   
Jean DAndrea Senior   Retired
Thanks for the table code, BJ, have saved it and will play later.

Have been using tables for a while, but haven't always been successful.
CSS is still a closed book to me, but one day......

Jean
Nov 2nd 2007 19:46   
Wendy Senior   
Question

Have been working on BJ's advice and still running into difficulties

When I attempted to copy and paste from Notepad it alters evertyhing

It ends up looking like this (only a short copy not complete code)

&lt;td align="center" colspan="3"&gt;&lt;span style="COLOR: #ff0000"&gt;&lt;b&gt;

Why is that ??? What can i do about it??

Wendy
Nov 2nd 2007 19:55   
Bj aka Bill Brown Magnate I   Hosting and Backup Service provider
hi Wendy,

&lt;td align="center" colspan="3"&gt;&lt;span style="COLOR: #ff0000"&gt;&lt;b&gt;

should look like

<td align="center" colspan="3"><span style="COLOR: #ff0000"><b>

somehow the < and > are being converted to &lt; and &gt;

in a web page if its put in thecode as &tl; or &gt; it will litterally show the < and >
instead of telling the browser that it is a funcuion.

Why this should be happening I do not know.

span style="COLOR: #ff0000"
is the same as font color="#ff0000"

I have noticed that the system here in APSense will convert some commands but that is nothing to worry about they are both correct.


My big question is
when you have the box in which to enter your post content did you click on the tab at the bottom of the box marked HTML first before pasting the code?

I have a feeling you are entering the code into the Design option in which case it well assume you want to display exactly what you enter and convert the < and > so that it can be displayed.





Nov 2nd 2007 20:25   
Wendy Senior   


Yes I am using the html format to add the codes to my page and I still end up with the all the other junk

Wendy


Nov 2nd 2007 21:02   
Please sign in before you comment.