Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make table borders invisible with CSS

I know this is an oft asked question, but I've tried some of the solutions (such as How to make separating lines/borders in a table disappear with CSS?) but I still can't quite get it.

I have defined via css a table structure with alternating row colors. I'd like the (in particular vertical) borders between teh cells to be invisible and so suppose I either need a zero td border width, or the alternating td border colors to be the same as the background colors.

Example below is what I've tried, in calling a table1 id from html, I get a nice alternating colored row table but with obvious cell borders still - appreciate your help.

#table1 table, tr, td, th {
     border: 0;
}

#table1 tbody tr:nth-child(odd) {
     background-color: #A3B9D2; 
}

#table1 tbody tr:nth-child(even) {
     background-color: #E7EDF3;
}

and then sample html;

<table id="table1" >
   <tr>
     <td>Test</td><td>(value)</td>
   </tr>
   <tr>
     <td>Test2</td><td>(value2)</td>
   </tr>
</table>
like image 972
vinomarky Avatar asked Feb 08 '12 05:02

vinomarky


People also ask

How do I remove a table cell border in CSS?

This is a Default behavior of the table cells that there is some space between their Borders. To remove this space we can use the CSS border-collapsing Property. This Property is used to set the borders of the cell present inside the table and tells whether these cells will share a common border or not.

Can we have tables without borders?

The table without borders is a design view of the web page using an HTML table. The use of the table simplifies the presentation of the large information in the simplest form. Table with or without borders used for comparison in between the items.


1 Answers

It's possible that what you're describing is cellspacing. If that's the case try this in your HTML:

<table cellpadding="0" cellspacing="0" border="0">
  ...
</table>

Cellspacing refers to the space between cells; it's not a border exactly. So, if you're seeing invisible or non-colored spaces between your tds, try adding the cellspacing="0" attribute to your table tag.

like image 140
Tracy Fu Avatar answered Oct 19 '22 07:10

Tracy Fu