![]() |
|
| ||||||||||||||
Anatomy Of A TableA table is an organized presentation of data in rows and columns. HTML has a special set of tags and attributes for making tables. Below is a diagram of the parts of a table. ![]() Tables can become very complex and are a popular way to layout web pages. They are particularly good at making columns on web pages. Lets start at the beginning and try to make the table pictured above. Basic Table TagsTables are coded with HTML tags in the <body> of your page. There are three primary tags used in making tables. The first is the <table> tag. All of the rows and cells in a table are all nested inside the <table> and </table> tags. We'll start making our first table by coding the <table> tags:
<body> Nothing tricky here. The <table> tags define the table as opposed to other content in the <body>. You can code any content you want outside the <table> tags and they'll be displayed outside the table as usual. Next we'll make the "rows". Rows go across the page and are made with <tr>, or Table Row, tags. In our example there are two rows. We'd code these rows like this:
<table> First notice that we've used two sets of <tr> and </tr> tags. Each set makes one row. The above code defines two rows for our <table>. Columns are made by the Table Data tags, the <td> tags. These tags make the cells, columns, and hold the content. Note that content, like text, does *not* go between either the <tr> or <table> tags themselves. It goes inside the <td> tags.
<table> And that is all it takes to make a simple two row, two column (2x2) table like the one at the top of this page. Things to remember:
ExercisesMake the <table>s below before moving on. Note that the tables you code will be to the left of the page when viewed in a browser. We'll see how to center them in the next lesson. Worry about coding the basic table for now. Remember that <tr>s make rows and <td>s make cells, columns, and hold content.
After making the tables above, do some experimenting with larger tables with more rows and columns. Try putting more text than "Cell #x" in the cells. Put an image in a cell. (Hint: just nest an <img> tag inside the <td> tags.) |
||||||||||||||
| ||||||||||||||