ChetOS.net

CSS replacement for Table Cellspacing and Cellpadding

It is a bit clunky and "technically" inappropriate to use <table cellspacing="0" cellpadding="0" /> because those are presentation level attributes and HTML is suppose to be strictly content level... it is splitting hairs, I know.  However, this is the current push.

So, after years of using those attributes knowing it was incorrect, I decided to find the proper CSS way.  It is actually very simple and it works on all modern browsers.

In your CSS declaration for the table include {border-collapse:collapse;} and for the TD use {padding:3px;margin:0px;}.

If you are using the width or height attributes in your CSS including the padding will mess it up... just be sure to subtract (Padding X 2) from the width and height.

Hope that helps.
Posted by Chet at 5:03 PM

Comments

I used "table{border-spacing:..}" as a replacement for "cellspacing" and "td{padding:...}" for "cellpadding".
Posted by ... at 2:37 PM on Sun, Feb 5, 2006

test
Posted by Anonymous at 11:14 AM on Thu, Jul 24, 2008

Used table{border-spacing:..}" as a replacement for "cellspacing" and "td{padding:...}" for "cellpadding"...
works on firefox 3.6.8, IE 8 and Chrome
Posted by SDT at 12:38 PM on Fri, Aug 13, 2010

Post a Comment

Feel Free To Share Your Thoughts
You can use [b], [u], [i], and [url]
Optional
Name
Website
© 2013 Chet Zema π