The early Web was used to communicate data between Universities and one of the most common structures used for that purpose is a table. Even today, many tables use the default styles, which makes them somewhat boring. In this article, I show you how to use CSS (cascading Style Sheets) to make your tables more interesting.
Welcome to Bucaro TecHelp!

Welcome to Bucaro TecHelp!
Maintain Your Computer and Use it More Effectively
to Design a Web Site and Make Money on the Web

[About BTH]  [User Agreement]  [Privacy Policy]  [Site Map]  [Contact Form]  [Advertise on BTH]  [News Feed]

Google
Web
This Site

How to Style a Table

The early Web was used to communicate data between Universities (as apposed to its primary use today: advertising, social banter, and pornography ... pardon my diversion) and one of the most common structures used for that purpose is a table. Even today, many tables use the default styles, which makes them somewhat boring. In this article, I show you how to use CSS (cascading Style Sheets) to make your tables more interesting.

Below is a basic table with no style applied.

Table Caption
Col1 TitleCol2 TitleCol2 Title
Row 1 Col 1Row 1 Col 2Row 1 Col 3
Row 2 Col 1Row 2 Col 2Row 2 Col 3
Row 3 Col 1Row 3 Col 2Row 3 Col 3

Note that each cell in the table has its own border, making it look like the table has a thick border. This is caused by the fact that IE puts some spacing between the cells. By setting the html attribute cellspacing=0 you can put the cell borders next to each other, as shown below, but that won't collapse them into a single border like you would have in a spreadsheet.

Table Caption
Col1 TitleCol2 TitleCol2 Title
Row 1 Col 1Row 1 Col 2Row 1 Col 3
Row 2 Col 1Row 2 Col 2Row 2 Col 3
Row 3 Col 1Row 3 Col 2Row 3 Col 3

The style property border-collapse sets whether the cell borders are collapsed into a single border as shown below.

<table border=1 style="border-collapse:collapse;">
<caption>Table Caption</caption>
<tr><th>Col1 Title</th><th>Col2 Title</th><th>Col2 Title</th></tr>
<tr><td>Row 1 Col 1</td><td>Row 1 Col 2</td><td>Row 1 Col 3</td></tr>
<tr><td>Row 2 Col 1</td><td>Row 2 Col 2</td><td>Row 2 Col 3</td></tr>
<tr><td>Row 3 Col 1</td><td>Row 3 Col 2</td><td>Row 3 Col 3</td></tr>
</table>

Table Caption
Col1 TitleCol2 TitleCol2 Title
Row 1 Col 1Row 1 Col 2Row 1 Col 3
Row 2 Col 1Row 2 Col 2Row 2 Col 3
Row 3 Col 1Row 3 Col 2Row 3 Col 3

Collapsing the cell borders alone greatly improves the appearance of a table, but still not the best we can do.

Web Design Sections

RSS Feed RSS Feed

Cascading Style Sheets
Understanding CSS Selectors
The CSS Box Model
Understanding CSS Positioning
Add Style to Your Blockquotes
Display Overlapping Images on Your Webpage
Add Drop Shadows to Your Pictures
Style Your Imagemap Tooltips
How to Style a List
How to Style a Table
How to Change the Mouse Pointer
How to Use a Starburst on Your Web Page
How to Use a Pull Quote
Easy Scrollable Area Code
Easy CSS Buttons
Create CSS Button Rollovers
Create Custom Horizontal Rules
Easy CSS Popup Windows
Easy Visual Effects to Spice Up Your Webpage
Spice Up Your Web Forms with Color and Graphics
Setting a Larger First Letter
Make a Fixed-width Variable-height Round Cornered Box
HTML, XHTML, and CSS Bible
Web Designer's Reference
Pro CSS Techniques
Code for Horizontal Drop-down Menu Bar
Easy Rollover Menu Code
Easy CSS Tabbed Navigation
Easier Expanding Menu Code
Easy Three-level Expanding Menu Code
Easy Floating Menu Code


Your Career Quiz
[Site User Agreement]  [Advertise on This site]  [Search This Site]  [Contact Form]
Copyright©2001-2009 Bucaro TecHelp P.O.Box 18952 Fountain Hills, AZ 85269