Styling HTML Tables with TableCloth

In this tutorial I will show you how to apply some simple style to your tables by applying the TableCloth style sheet and JavaScript file. TableCloth is a free, light way, way to add style to existing HTML tables. It only required two lines of code added to your table. With table clothe you can also modify how the HTML tables react to your input by changing the JavaScript file.

First you will need to download the TableCloth files from CSS Globe.

Extract the files and save them, we will use them later. For the next part of the tutorial we need to have a table made already. If you don’t have a table made you can use this code

<html>

<head>

<title>Styling Tables with TableCloth</title>

</head>

<table>

  <tr>

  <th>First Name</th>
  <th>Last name</th>
  <th>Age</th>

  </tr>

  <tr>

    <td>John</td>
    <td>Ward</td>
    <td>21</td>

  </tr>

  <tr>

    <td>Mike</td>
    <td>Maguire</td>
    <td>21</td>

  </tr>

  <tr>

    <td>Sara</td>
    <td>Lee</td>
    <td>61</td>

  </tr>

  <tr>

    <td>Walter</td>
    <td>Reed</td>
    <td>1</td>

  </tr>

</table>
</html>

Save the file as table.htm and open it with your browser. The table should look like this
Styling HTML Tables with TableCloth

The table is very plain looking, but that can be changed with a few lines of code. We will add two lines of code in the head of our page.

Styling Tables with TableCloth

Now we need to copy the tablecloth folder into the directory with our table.htm
Styling HTML Tables with TableCloth

Note that there are two folders named “tablecloth” when you extract the files, we want to copy the folder that contains these files:
Styling HTML Tables with TableCloth

After you copy the files over and add the changes to the header of table.htm, refresh the page. Your table should now be styles by tablecloth.
Styling HTML Tables with TableCloth

By default the table columns are highlighted when you hover over them with the mouse.
Styling HTML Tables with TableCloth

Also when you click on an item the entire columns turns a green color.
Image06

These values can be changed in the tablecloth.js file which is located in the tablecloth folder. This info is near the top of the file in the config section.

	// if set to true then mouseover a table cell will highlight entire column (except sibling headings)
	var highlightCols = true;
	
	// if set to true then mouseover a table cell will highlight entire row	(except sibling headings)
	var highlightRows = false;	
	
	// if set to true then click on a table sell will select row or column based on config
	var selectable = true;

So if you wanted only the rows to be highlighted you would change the config to look like this.

	// if set to true then mouseover a table cell will highlight entire column (except sibling headings)
	var highlightCols = false;
	
	// if set to true then mouseover a table cell will highlight entire row	(except sibling headings)
	var highlightRows = true;	
	
	// if set to true then click on a table sell will select row or column based on config
	var selectable = true;

Then the table would look like this on mouse over.
Styling HTML Tables with TableCloth

You can even highlight both column and row if you would like or turn of the green highlighting on click. As you can see the file is easy to manipulation and the lines are commented so it should be easy to figure out. There is also a CSS file included that you can modify. I am not going to go into modifying the default style in this tutorial. All it takes to modify the style is some basic CSS knowledge.

Subscribe To Our Newsletter

Subscribe To Our Newsletter

Join the TeamTutorials mailing list and get the latest tips, tricks, and special discounts for members only.

Thanks! Please click the link in the email we just sent you to confirm.

  • Pingback: Styling HTML Tables with TableCloth : infoeduindia multimedia collection()

  • thanks

  • vasile

    I’m new to css. How could I exclude one table from your css file.

    I have 4 tables, which I want to take the tablecloth attributes, but the fifth table, I want to be a plane simple table, without using any css(tablecloth)?

  • i am professional in creating tables in html but right now, i am practicing how to do layout using css.

  • I’d do it either way, cause I don’t see too many people on here doing it, people need to stop using tables for layouts. that’s not what tables were meant for, tables are for TABULAR DATA.