Creating tables can be error prone and difficult using the older HTML tags. In addition, they prove inflexible at times. It’s possible to create tables using another technique. All you need is a series of cascading
Many developers have used tables for all sorts of tasks in the past. Of course, there is the use of tables to display data. However, tabular arrangements are also useful for creating forms to ensure the various elements align in a predictable manner. This second use of tables is problematic because it confuses some software such as screen readers. The problem becomes one of defining a well-organized page without creating problems for the people viewing it.
Using
Defining the HTML for a
<div class="Table"> <div class="Title"> <p>This is a Table</p> </div> <div class="Heading"> <div class="Cell"> <p>Heading 1</p> </div> <div class="Cell"> <p>Heading 2</p> </div> <div class="Cell"> <p>Heading 3</p> </div> </div> <div class="Row"> <div class="Cell"> <p>Row 1 Column 1</p> </div> <div class="Cell"> <p>Row 1 Column 2</p> </div> <div class="Cell"> <p>Row 1 Column 3</p> </div> </div> <div class="Row"> <div class="Cell"> <p>Row 2 Column 1</p> </div> <div class="Cell"> <p>Row 2 Column 2</p> </div> <div class="Cell"> <p>Row 2 Column 3</p> </div> </div> </div>
Notice that each
The CSS for this table uses a few special properties and a little clever formatting. Here is the CSS used to make this example functional.
<style type="text/css"> .Table { display: table; } .Title { display: table-caption; text-align: center; font-weight: bold; font-size: larger; } .Heading { display: table-row; font-weight: bold; text-align: center; } .Row { display: table-row; } .Cell { display: table-cell; border: solid; border-width: thin; padding-left: 5px; padding-right: 5px; } </style>
Notice the use of the display property. This is the crucial property for your table because it tells the browser how to display a particular element. Otherwise, there isn’t anything strange of out of the normal about these styles. You define text attributes that help viewers differentiate between various table elements. Cells are separated from each other using a simple border. The following figure shows you how the table will appear when you view it in a browser.