Let’s suppose we have some tabular data that we want to mark up with HTML. HTML has a <table> element to take care of marking up tabular data. Before we dive into the <table> element, let’s first get an idea of what goes into a table. As you can see, we have columns entitled City, Date, Temperature, Altitude, Population, and Diner Rating. The first row is the headings of the table (bolded below). Then, we have 6 additional rows of data. We call each piece of data a cell or sometimes just table data.
1. Using the code above to start, finish typing in the table data from the previous page into a file called table.html in a folder called assignment5-3 on your PC. Make sure your page includes the minimal HTML 5 code as well.
2. Make sure your table renders the same as the image above in your favorite browser.
3. Make sure your page validates using the W3C validator as well (it is easier to make corrections after making a few changes than at the very end).
4. Once this is done, we need to use some embedded CSS to add some styling as outlined below. Copy the table.html file to table_orig.html so you have a backup copy if you mess up and need to start over again. You will continue to make changes to the
table.html file going forward.
a. First we’ll style the table (table). We need to add a margin on the left and right of 20 pixels and a thin sold black border to the table. We also need to reposition the placement of the caption to the bottom of the table.
b. Let’s change the border on the table data cells (td and th) to be a thin dotted border in gray and let’s add some padding to the data cells so there’s 5 pixels of space between the data content and the border.
c. Last, let’s change the caption so the font-style is italic and the padding at the top is 8 pixels.
5. The changes above should change your table to look like the image below:
Note that this property may not be supported in all browsers. Use the latest Firefox or Google Chrome browser version to ensure compliance.
6. Make sure your table renders the same as the image above in your favorite browser.
7. Make sure your page validates using the W3C validator as well.
8. Now we’ve got a dark border and dotted lines. And we’ve got some margin on the table and some padding in each table cell.
Those dotted lines are looking really busy and distracting though and they are duplicated between each pair of table cells. As you see above, table cells have padding and a border—just like you’ve seen in the box model—but they are a little different when it
comes to margins. The box model is a good way to think about table cells, but they do differ when it comes to margins. Let’s take a look at one of the cells in Jeff’s table:
12. Make sure your table renders the same as the image above in your favorite browser.
13. Make sure your page validates using the W3C validator as well.
14. Let’s add some color to the table headers (th) to make them easier to read. To do this, simply set the background-color property on the table headers to change their color to #cc6600 using CSS. We will also want to give rows an alternating color, which allows
you to more easily see each row without getting confused about which column goes with which row. First, we’ll define a new class called cellcolor. Then we’ll add this class attribute to each row you’d like to color with a value of #fcba7a. So for our table, we
will add class=”cellcolor” to each of the <tr> opening tags for Idaho Falls, Denver, and Tuscon
15. Make sure your table renders the same as the image above in your favorite browser.
16. Make sure your page validates using the W3C validator as well.
17. As it turns out, Jeff returned to Radium Springs, NM (on August 27th) to visit a new friend he made while there the first time.. He would like to add this entry to the table as is shown below.