Advertisement
Advertisement


Removing unwanted table cell borders with CSS


Question

I have a peculiar and frustrating problem. For the simple markup:

<table>
    <thead>
        <tr><th>1</th><th>2</th><th>3</th></tr>
     </thead>
    <tbody>
        <tr><td>a</td><td>b></td><td>c</td></tr>
        <tr class='odd'><td>x</td><td>y</td><td>z</td></tr>
    </tbody>
</table>

I apply different background-color values to the thead, tr, and tr odd elements. The problem is that in most browsers, every cell has an unwanted border which is not the color of any of the table rows. Only in Firefox 3.5 does the table have no borders in any cell.

I'd just like to know how to remove these borders in the other major browsers so that the only thing you see in the table are the alternating row colors.

2017/05/20
1
84
5/20/2017 3:51:37 PM

Accepted Answer

You need to add this to your CSS:

table { border-collapse:collapse }
2013/10/20
206
10/20/2013 5:37:33 PM

add some css:

td, th {
   border:none;
}
2010/01/11

Modify your HTML like this:

<table border="0" cellpadding="0" cellspacing="0">
    <thead>
        <tr><td>1</td><td>2</td><td>3</td></tr>
     </thead>
    <tbody>
        <tr><td>a</td><td>b></td><td>c</td></tr>
        <tr class='odd'><td>x</td><td>y</td><td>z</td></tr>
    </tbody>
</table>

(I added border="0" cellpadding="0" cellspacing="0")

In CSS, you could do the following:

table {
    border-collapse: collapse;
}
2017/10/04

to remove the border , juste using css like this :

td {
 border-style : hidden!important;
}
2017/04/02

Set the cellspacing attribute of the table to 0.

You can also use the CSS style, border-spacing: 0, but only if you don't need to support older versions of IE.

2010/01/11

You may also want to add

table td { border:0; }

the above is equivalent to setting cellpadding="0"

it gets rid of the padding automatically added to cells by browsers which may depend on doctype and/or any CSS used to reset default browser styles

2012/03/12

Source: https://stackoverflow.com/questions/2039438
Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Email: [email protected]