Skip to main content

basic html tables

Hey all,

I figure that I would expose you guys to the basics of creating tables in html. There are many ways to do this. The wysiwyg way of constructing a table would be to use the built-in eCollege table wizard, or to build a table in in MS Office or Dreamweaver. These methods offer limited customization, as is the nature of visual editors. In order to really customize every aspect of the table, you must have a working knowledge of the html used to create the table.

The basic elements of a table are as follows:

This is what the code for a basic table with a border looks like. And this is what that table would look like:

row 1, cell 1 row 1, cell 2
row 2, cell 1 row 2, cell 2

The elements include table rows <tr> and table definitions <td> which are the individual cells. { As an aside, if you ever want to include an empty cell in a table, make sure you put the code: &nbsp;. That is html talk for a non-breaking space. Nothing will show up in the cell, but if you don't have at least a space in there, the cell itself might not show up. The code with the definition would look like <td>&nbsp;</td> }

below is an example of what table borders look like. In short they look awful. On the left is the code and on the right is the execution:

With a normal border:

First Row
Second Row

With a thick border:

First Row
Second Row

With a very thick border:

First Row
Second Row

Here is what the code for tables looks like which have various numbers of row and columns:

Each table starts with a table tag. Each table row starts with a tr tag. Each table data starts with a td tag.

One column:

100

One row and three columns:

100 200 300

Two rows and three columns:

100 200 300
400 500 600

A basic note about html is that every time you open a tag, you must close it. So every <div> needs a </div>, and every <td> needs a closing </td>. Thus you need to keep track of all your <tr></tr>'s and <td></td>'s. If you build a 3x3 table, make sure that every row has three cells. Such would look like:

If you do not want any border, then either write it <table border="0"> or <table>. Now to add a little more to the tables, it is really easy to include captions and headers. Headers are similar to putting <b>bold</b> within the cells, but is a more proper and much cleaner way to do so. You can assign any cell to be a header cell, but for continuity they are typically either vertically or horizontally aligned. Here are some examples of captions and headers:

Monthly savings
Month Savings
January $100
February $50

Balance Sheets
  Revenue Profit
First Quarter $100m $21m
Second Quarter $90m $17m
Third Quarter $95m $18m

Now suppose you want a cell that spans more than one column or more than one cell. You would define that within the cell by using the following tag: colspan="[the number of cells it should span]". A quick example below:

Cell that spans two columns:

Name Telephone
Gia Graves 555 77 854 555 77 855

Cell that spans two rows:

Name: Sean Duffy
Telephone: 444 77 467
444 77 832

If you would like to include cell padding (which I almost always do), then you can include that information within the <table> tag. Cell padding is basically like putting space between the content of the cell and the border or wall of the cell. Some examples below:

Without cellpadding:

First Row
Second Row

With cellpadding:

First Row
Second Row

With lots of cellpadding:

First Row
Second Row

One final attribute I will cover in this blog post is defining widths and heights for tables or cells. There are two different ways to define the the attributes for the width or height. You can either specify pixels or percentages

Value Description
pixels Sets the width in pixels (example: width="50")
% Sets the width in percent of the surrounding element (example: width="50%")

In case you are wondering what the code for the above table looks like:

So these are the basics of what a table looks like in the code. With a little practice, coding a table from scratch can become as easy as creating an un/ordered list (also very easy). In a future post I will cover inline css edits and styling. These "bells and whistles" (sorry for the buzwords, Gia!) can be simple, but they can also be very cluttered. The main problem with the wysiwyg editors is that the more you tweak them, the more cluttered the code gets. Often the tweaks write additional code, instead of replacing code. So on one line you might find width="65%", but further down on the same line you might find a bit of code that reads width=227.3pt. These two attributes might mean different things, but the poor web browser can only accept one value. Also, if you copy a table from Word or Excel into a visual editor (eCollege, dreamweaver, etc.), it is hard to tell what the code will look like.

Just to show you how unnecessarily messy the code can get, below is a table that I modified this afternoon for PB536. As an exercise, try to see how much of the table you now understand based on what you learned from this post:

 
Post Type
Post Composition
Points

Initial Post

The first post for every discussion should exhibit a strong statement to answer, or partially answer, the main discussion question.

This answer should incorporate a concise statement backed by readings from the class or another source, and it should stimulate further discussion.
  • 5 points analysis of article
  • 2 points for each discussion question posed

9

Reply

Each student should reply to a minimum of three other initial posts per week.

Good answers address the post, are supported by readings or other facts, and challenge other participants to further explore the topic.

4 points each

Total
 

21 points


  • Participants are free and encouraged to post more than the required minimum, and those posting more than the minimum can positively impact the course participation grade at the end of the term!
  • Please note that discussions take place across the week, and not as an assignment to post last minute! Let your peers profit from what you have to share!

Comments

  1. by the way, that last table is an example of "bad" html. I modified an existing table so that it would look good within the eCollege frame, but I made no effort to clean the code. Resultantly, you get things like...

    <font size="4"><font color="#f2f2f2"><font face="Arial">Post Type</font></font></font>

    ...as opposed to something cleaner:

    <font face="Arial" color="#f2f2f2" size="4">Post Type</font>

    ReplyDelete
  2. Sadly, that is one of my tables created from Word. I know it adds alot of extra junk, but HTML tables confused me until now.

    Thank you so much for showing me how to simplify this. Can you please give me the quick code for that color blue as the heading to the table as well as what the border color code is?

    ReplyDelete

Post a Comment

Popular posts from this blog

Encouraging student voice and video comments

Hey team, Won and I are at the Sloan-C Emerging Technology conference (#et4online), and I wanted to share some ideas with you all regarding the utilization of audio and video features in our discussion boards.  The presenter who inspired this post is Michelle Pacansky-Brock who wrote an ebook about VoiceThread. Her institution bought a site license so that students could make comments on VT via phone, ensuring that technology wouldn't be a barrier to student participation. My thoughts are that our online and most blended students have both computers with webcams/microphones and smartphones. I think that in Canvas we don't need to rely so much on VT to facilitate an audio/visual discussion, as these features are integrated into the learning platform. Michelle conducted research in her classes via surveys and discovered that when she as an instructor left voice and video comments, 97% of the students appreciated such comments. However, 75% of the students were unwilling ...

What's all this talk about APIs?

These application programming interfaces (APIs) are all the rage these days.  We hear about them in online commerce, social media, and now they are flooding the world of education and online learning.  So what are they exactly? An API is a way for websites, programmers, and applications to communicate with each other, exchanging information.  If I have a database with information that I would like to disseminate then I can develop an API and make that accessible to the world.  External developers can then create APIs with the purpose of communicating with my  API, and thus extract the information that I am making public.  It's similar to the notion of "my people will contact your people and we'll make this happen".  Only the people in mention is actually a software-to-software exchange. Why APIs are important APIs are a way to access information or databases which would otherwise be inaccessible.  For example, my database might be protected ...

Recap of L&L

I just wanted to put up a recap of what I went over yesterday. This should be useful for Nicole and Gia, who didn't make it for that portion, as well as for anyone who would like to go over that again. The short description of my portion yesterday was that there are a wealth of resources and materials built right into PowerPoint that most people don't know about (or they don't realize the possibilities available). We are able to take what is given to us and modify it and truly make it our own.