css2 comes to the rescue

remember how sometimes you wish to put a colored border around all table cells so all of them have a border of one pixel? unfortunately, this can be aggravatingly difficult to achieve with the border properties in CSS. The first thing you’d be likely to try might be:

table {
border-style: none;
}
td, th {
border: 1px solid black;
}

This puts the border described around each table cell. But the borders of adjacent cells combine visually to produce a 2-pixel border between cells.

Until recently, the best way to handle this was to apply borders only to the top and left edges of cells, and then add a bottom and right border to the entire table:

table {
border-top: none;
border-right: 1px solid black;
border-bottom: 1px solid black;
border-left: none;
}
td, th {
border-top: 1px solid black;
border-right: none;
border-bottom: none;
border-left: 1px solid black;
}

This is messy to say the least. Fortunately, the CSS2 border-collapse property comes to the rescue:

table {
border-collapse: collapse;
}
td, th {
border: 1px solid black;
}

The border-collapse property instructs the browser to combine the borders of adjacent table cells, collapsing them together. Browsers that support this include Internet Explorer 5 for Windows, Netscape 6, Mozilla, and Opera 7.


1 Comment Leave a Comment

Daynah [ Quote ]

oh wow!! That’s neat sis. Thanks for the tip! :)

May 14th, 2003 at 10:43 pm

Leave a Comment Name, email and comment are required.
Email will never be displayed.

Leave a Comment
  1. :biggrin: :blank: :blush: :bored: :confused: :cool: :down: :evil: :frown: :grin: :grr: :laidback: :left: :mad: :right: :sad: :secret: :shock: :smile: :stress: :tongue: :up: :wink: :yawn: :cute: :dead: :film: :floppy: :glasses: :grumpy: :headphones: :heart: :lightbulb: :ouch: :tv: :upsidedown: :vodka: :yell: :yuck: :yummy: