Page is a not externally linkable
- Code, Content, and Presentation
-- CSS
---- How to get a table border separate from the cell border.


MichaelBluejay - 11:53 pm on Sep 29, 2012 (gmt 0)


I'm trying to get all my table cells to have a 1px silver border, and the table itself to have a 1px black border. I don't care whether the black border replaces the silver square around the table, or whether it sits outside that square. I just can't get either to work. Not without lots of code, anyway.

Here's the HTML:
<table> 
<tr><td>1</td><td>2</td><td>3</td></tr>
<tr><td>4</td><td>5</td><td>6</td></tr>
<tr><td>7</td><td>8</td><td>9</td></tr>
</table>

This gets me the separate black border, but the cell borders are then doubled to 2px:
<style type=text/css> 
table {border:1px solid black; border-spacing:0px}
td {border:1px solid silver; padding:10px}
</style>

Adding "border-collapse:collapse" to the table makes the cell borders 1px as they should be, but then the black border disappears.

Curiously, the border-collapse version works if I change the cell border style to "dotted". In that case the black border magically appears. But then I'm stuck with a dotted border, and dotted borders are for losers. I can't get this to work with solid borders.

What's the simplest way to achieve a separate table border from solid cell borders, all of which are 1px?


Thread source:: http://www.webmasterworld.com/css/4501794.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com