SunQuest
 
       HTML
  Home arrow HTML arrow Page 7 - HTML, CSS and Tables: The Beauty of Data
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Dedicated Servers  
Actuate Whitepapers 
Moblin 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
HTML

HTML, CSS and Tables: The Beauty of Data
By: Chris Heilmann
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 66
    2004-11-17

    Table of Contents:
  • HTML, CSS and Tables: The Beauty of Data
  • What is a table?
  • W3C to the rescue
  • Summary needed
  • Styling tables: the days of the spacer GIF
  • Embracing CSS and separating "what is what" and "what it looks like"
  • Our CSS

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    HTML, CSS and Tables: The Beauty of Data - Our CSS


    (Page 7 of 7 )

    We start by defining a black border around the table and making sure that there is no spacing in between the cells. We also define the font size and family (this could be inherited from the body element, too).

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

    We repeat the border information for all of the inner elements and set their padding to 5 pixels.

    td,th{
     border:1px solid #000;
     border-collapse:collapse;
     padding:5px;
    }
     

    We use the IDs of the headers to define the width of the columns (this could also be achieved via a colgroup and col definition in the HTML, but this is more flexible).

    #fn,#dp,#ar{width:58px;}
    #fr,#to{width:138px;}

    Next on our list is the caption. It needs a background, a slightly larger font and a border. As our caption sits on top of the table, we have to get rid of the bottom border. Texts in captions are centered by default, therefore we need to set the text-align to left.

    caption{
     background:#ccc;
     font-size:140%;
     border:1px solid #000;
     border-bottom:none;
     padding:5px;
     text-align:left;
    }

    The same applies to headers, and to distinguish between headers in the head and those in the body of the table, we use descendant selectors:

    thead th{
     background:#9cf;
     text-align:left;
    }
    tbody th{
     text-align:left;
     background:#69c;
    }

    The same descendant selectors help us defining the differences for the data cells:

    tfoot td{
     text-align:right;
     font-weight:bold;
     background:#369;
    }
    tbody td{
     background:#999; 
    }
    tbody tr.odd td{
     background:#ccc;
    }

    Voila, our table is styled. You might have realized that we still need a class if we want to have alternate row colors. In CSS3 we will have a chance to avoid that, via the n-th child selector, or alternatively, we can use a Javascript to add the alternate line classes for us.

    More reading

    This tutorial should only give you an insight of what is possible when you ditch old school solutions and embrace a cleaner structure. By using the right markup and creating CSS that uses inheritance and descendant selectors we can cut down the amount of markup drastically, make it easier to maintain, and accessible to boot.

    If you want to know more about the taming of HTML tables, read the following:


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · The article is only the start. I hope some of you might be tempted to go on...
     

    HTML ARTICLES

    - Building Single Row Database Forms with HTML
    - Introduction to Database Forms with HTML
    - Another Look at Animation of Geographical Ma...
    - Animation of Geographical Map Regions
    - Changing and Moving Pictures with CSS
    - Clickable Geographical Map Regions
    - Gradient Creation with the HR Element
    - Text on HTML Images: Do it Yourself
    - Custom Buttons in HTML
    - Quick Web Page Menu
    - Maximizing and Restoring HTML Images with th...
    - Maximizing and Restoring HTML Images with th...
    - Handling Hyperlinks and Images in HTML
    - Quick Start with HTML
    - HTML Tips






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway