| TheScriptCenter.com |
|
[BGCOLOR & BORDERCOLOR] [BACKGROUND] [WIDTH & HEIGHT] [ALIGN & VALIGN] [COLSPAN & ROWSPAN] [CELLPADDING & CELLSPACING]
By Jason J. Russo
|
If you read my last article How to make a webpage I showed you the basic ingredients of building a webpage on your own. In this article I'm going to show you how to build HTML tables. With the advent of CSS, websites are using
tags and positioning elements more and more. Personally,I always like to use a little bit of . A little bit dab of CSS, little dab of JavaScript, little dab of Ajax, html, php, and I'm a happy camper. DIV's are cleaner no question, and you can position keyword rich HTML elements towards the top of your page, but if someone is using an older web browser your site would look messy; if that's even something to really be concerned about I don't know. If you want to have some fun download Netscape 4.79 and surf the web. It's pretty interesting.
Let's look at the basic elements of a table: <TABLE>: -- defines the beginning of our table element. <TR>(table row): -- defines a new row of our table. <TD>(table dimension): -- defines a cell in that row. Other tags are: <TH>(table heading): This would be considered a heading but I honestly never use this tag or really see the benefits of using it at all. <TBODY>(table body), <THEAD:>(table head),<TFOOT>(table foot): Again, I only use the 3 basic tags above and never use these tags at all. All I've ever needed was the basic 3. For our first table we'll start with a basic table with 2 rows, and 1 cell in each row. I placed a border on this table for this example so that you can see where the table rows, and cells are.
Video Tutorial Now that we've build our basic table, lets look at some of the other attributes we can use. In the next examples I'll show you some common html table attributes. A key thing to remember is that all your attributes go between the start of your tags: <TD ATTRIBUTE=""> and before the end of your tag. BGCOLOR: background color. This can be used inside TABLE,TR,and TD tags. BORDERCOLOR: Border Color, pretty much self explanatory.
Video Tutorial In the above example I used bgcolor="" attribute to make my tables background color blue and bordercolor="" to make the border color black: <table border="1" BGCOLOR="blue" BORDERCOLOR="black">. Aside from bordercolor, the same rule applies for rows and cells of your table. BACKGROUND: Display a background image. This attribute can be used in your TABLE, and TD, tags.
Video Tutorial I used background="" attribute to set a background image in top 2 table cells. WIDTH & HEIGHT: This can be used inside your TABLE, and TD tags.
Video Tutorial In the above example I used these attributes to make the width and height of my table 400 x 100 pixels: <table border="1" BGCOLOR="silver" WIDTH="400" HEIGHT="100">. ALIGN: This can be used inside your TABLE, and TD tags. ALIGN tag has 3 values, LEFT(by default), CENTER, & RIGHT. This attribute is used for aligning the table or the contents of your table cells. VALIGN (vertical alignment): tag has 3 values as well, TOP, BOTTOM, and MIDDLE. This attribute is used for vertically aligning the contents of your table cells.
In the above example I used these attributes to align the table to the center of the page, center the text in cell 2, vertically align the text to the top of the cell in cell one of the second row. <table border="1" BGCOLOR="silver" BORDERCOLOR="black" WIDTH="400" HEIGHT="100" ALIGN="CENTER">, <TD ALIGN="CENTER">, <TD VALIGN="TOP"> COLSPAN & ROWSPAN: Column Span and Row Span. These attributes define how many rows or columns your table cell will run. This rule only applies to the <TD> tag.
In the above example I used rowspan=3 in the first cell in order for the first TD tag to span 3 rows, in the cell next to it I used a colspan=2 in order for the cell to span 2 columns, and in the very bottom cell I used a colspan of 3 in order for the cell to stretch the sell along the entire length of the table. CELLPADDING & CELLSPACING: These attributes the padding and spacing between your table cells. This rule only applies to the <TABLE> tag.
In the above example I used a cellpadding of 15 pixels, and cellspacing of zero pixels. [Try It Out] |
||||||||||||||||||||||||||||||||||||