Home arrow HTML arrow Page 6 - HTML, CSS and Tables: The Beauty of Data
HTML

HTML, CSS and Tables: The Beauty of Data


Assistive technology gags when it encounters HTML tables coded by the old school methods. Using the new coding lets you make tables more accessible to your users, and it really isn't that much harder--just remember what a table really is. Chris Heilmann reminds us, and gives an introduction to CSS.

Author Info:
By: Chris Heilmann
Rating: 4 stars4 stars4 stars4 stars4 stars / 97
November 17, 2004
TABLE OF CONTENTS:
  1. · HTML, CSS and Tables: The Beauty of Data
  2. · What is a table?
  3. · W3C to the rescue
  4. · Summary needed
  5. · Styling tables: the days of the spacer GIF
  6. · Embracing CSS and separating "what is what" and "what it looks like"
  7. · Our CSS

print this article
SEARCH DEVARTICLES

HTML, CSS and Tables: The Beauty of Data - Embracing CSS and separating "what is what" and "what it looks like"
(Page 6 of 7 )

With MSIE6 and Gecko being released, we are able to completely separate the HTML markup and the presentation.

Instead of repeating the visual information or use a lot of classes in each HTML document, we create a roughly 700 bytes big CSS file and apply it to each of the documents. Instead of classes, we use the element names and use descendant selectors. Changes are done in the CSS exclusively. Removing the classes cuts down our table to 1.3KB and 30 lines of markup.

Creating the desired "hairline" effect of our table requires some CSS skill. A quite robust way of doing it is to define a border on the left and the top for the table, and a border on the right and the bottom for the inner elements like cells and headers in our CSS.

Our CSS:

table {
  border:1px solid #000;
  border-collapse:collapse;
  font-family:arial,sans-serif;
  font-size:80%;
}
td,th{
  border:1px solid #000;
  border-collapse:collapse;
  padding:5px;

#fn,#dp,#ar{width:58px;}
#fr,#to{width:138px;}
caption{
  background:#ccc;
  font-size:140%;
  border:1px solid #000;
  border-bottom:none;
  padding:5px;
  text-align:left;
}
thead th{
  background:#9cf;
  text-align:left;
}
tbody th{
  text-align:left;
  background:#69c;
}
tfoot td{
  text-align:right;
  font-weight:bold;
  background:#369;
}
tbody td{
  background:#999; 
}
tbody tr.odd td{
  background:#ccc;
}

However, to ensure that our lines meet, we need to set the cellspacing attribute in our HTML to 0, and cellspacing is a deprecated attribute for XHTML.

For XHTML documents we can use the border-collapse selector in the CSS to achieve the effect.

Lets take a look, shall we?

Our markup:

<table summary="This table lists all the flights by XYZ Air leaving London today.">
  <caption>Flight Schedule</caption>
  <thead>
    <tr>

      <th id="fn" scope="col">Flight Number:</th> 
      <th id="fr" scope="col">From:</th> 
      <th id="to" scope="col">To:</th> 
      <th id="dp" scope="col">Departure:</th> 
      <th id="ar" scope="col">Arrival:</th> 
    </tr>

  </thead>
  <tfoot>
    <tr>
      <td colspan="5">Total: 3 flights</td>
    </tr>

  </tfoot>
  <tbody>
  <tr>
    <th scope="row">BA 3451</th>
    <td>Heathrow</td>

    <td>Nuremberg</td>
    <td>19:20</td>
    <td>19:50</td>
  </tr>

  <tr class="odd">
    <th scope="row">BA 1254</th>
    <td>Luton</td>
    <td>Alicante</td>

    <td>19:40</td>
    <td>20:50</td>
  </tr>
  <tr>
    <th scope="row">LH 331</th>

    <td>Heathrow</td>
    <td>Hamburg</td>
    <td>20:00</td>
    <td>20:20</td>

  </tr>
  </tbody>
</table>


blog comments powered by Disqus
HTML ARTICLES

- Does HTML5 Need a Main Element?
- Revisiting the HTML5 vs. Native Debate
- HTML5: Not for Phone Apps?
- HTML5 or Native?
- Job Hunting? Freelancer.com Lists This Quart...
- HTML5 in the News
- Report: HTML5 Mobile Performance Lags
- The Top HTML5 Audio Players
- Top HTML5 Video Tutorials
- HTML5: Reasons to Learn and Use It
- More of the Top Tutorials for HTML5 Forms
- MobileAppWizard Releases HTML5 App Builder
- HTML5 Boilerplate: Working with jQuery and M...
- HTML5 Boilerplate Introduction
- New API Platform for HTML5

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials