A Tableless Table – Exploring the power of CSS3

The recent browser versions like Firefox 3, Google Chrome, Internet Explorer 8, Opera 9.5 and Safari 3 are now coming with a great and brand new support: CSS3. Some of the new properties are introduced and here I am going to describe the table value for the display property.

To align data in a tabular structure we can use a common table using the HTML tags <table>, <tr>, <td> nonetheless we all know that by using that we are violating the latest web standards, right?But hold on for a second. I’m just going to introduce you a hot new way to code it using nothing else than div tags with the great CSS3 and the data will appear just like a table. Believe, that’s true!

Here is an example:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Some Page</title>
<style type="text/css">
.table {
display: table;
width:100%;
}
.row {
display: table-row;
width:100%;
}
.cell {
display: table-cell;
border: 1px solid blue;
padding: 1em;
width: 33%;
}
.element1 {
background:#0099FF;
}
.element2 {
background:#00FF99;
}
.element3 {
background:#FFFF99;
}
</style>
</head>
<body>
<div class="table">
<div class="row">
<div class="cell element1">
<p><strong>Web Development </strong></p>
<p>PHP &amp; MySQL<br />
Ruby on Rails<br />
ActionScript 3.0 / Flash / Flex / Adobe Integrated Runtime<br />
Amazon Web Services<br />
Zend Framework<br />
JavaScript / AJAX<br />
XHTML &amp; CSS Scripting<br />
Content Management System</p>
</div>
<div class="cell element2">
<p><strong>Windows Development</strong></p></div>
<div class="cell element3"><p><strong>Mac &amp; iPhone Development</strong></p></div>
</div>
</div>
</body>
</html>

Screen shots:

Firefox 3

Google Chrome

Internet Explorer 8

Opera 9.5

Safari 3

Internet Explorer7

Working Principle:
The display property specifies a range of table-related values to make elements display and behave as they were table elements.

The new available display values for drawing tables are:
table to make the element behave like a table element
table-row to make the element behave like a table row (tr) element
table-cell to make the element behave like a table cell (td) element
table-row-group to make the element behave like a table body row group (tbody) element
table-header-group to make the element behave like a table header row group (thead) element
table-footer-group to make the element behave like a table footer row group (tfoot) element
table-caption to make the element behave like a table caption element
table-column to make the element behave like a table column (col) element
table-column-group to make the element behave like a table column group (colgroup) element

The table element in HTML is a semantic structure: it describes what data is. Therefore, you should only use the table element if the data you are marking up is tabular – for example, a table of financial information.

On the other hand, table value of the display property is simply an indication of how something should look in the browser – it has no semantic meaning. Using a table element for your layout tells the browser, “This data is tabular.”

Also we have to take care of, not to use display: table; property on a bunch of div elements when the data needs to be present in tabular format. Else simply avoid to use this property.

The main advantages on using this new structure are:

  • Place the data in tabular manner without violating the latest web standards.
  • No need of specify the cellpadding="0" cellspacing="0".
  • No need to make the border="0".
  • No need to make the margin and padding 0 of table, tr, td.
  • Print the page in tabular format without wired.
  • No need to specify the height, as the content added it will automatically adjust the height of the row and columns with specified background.

As we’re not living in Wonderland, we also have some disadvantages, as follow:

  • Only latest browsers support this property.
  • Mainly IE 7, IE6 are not supporting this property. They show the data in wired manner.

The solution would be to use this property only when we are going to develop a website for latest browsers and just ignoring the older versions. But as the statistics shows, most of the users still using IE6 and IE7.

To implement this in realistic world won’t be feasible to use CSS3’s advanced layout features for at least 4 or 5 years, once users need to upgrade themselves from the stone age of Internet to our beautiful high-tech development world.

3 users responded to this post

mygif Transition to CSS 3 « Lisa P. Maxwell said in January 12th, 2009 at 10:23 pm

[...] – Rounded corners on borders – Background Image updates – Background images on borders – Installable fonts – New Attribute Selectors – Opacity – Transforms: rotate elements on screen (Safari 3.0+ or Chrome only) This can change web design in a lot of ways by not only increasing the speed of development, but decreasing file size and server strain. It also opens up a whole new world of possibilities for design and development. For example, with the attribute selectors, the Stylesheet becomes a quasi-programming language with wildcards….for example, giving developers a bridge between ID’s (which are supposed to be unique on the page) and classes (which can be used many times on a page). Another example is using the display selector, you can tell block or inline elements to acquire all the display properties of a specific html tag. Want to create a table-less tabled layout? It’s possible with CSS 3. [...]

mygif ruskin012 said in August 10th, 2009 at 2:50 pm

This is right way to put the thing. You did a fabulous job.

mygif Arockia Dass said in June 24th, 2010 at 10:47 am

Ok

You must be logged in to post a comment.

full indir download