14

I have what seems like a simple problem, but searching the net hasn't yielded any results.

I have a table

<table>
    <tr>
        <td colspan="3">
            <img src="something.png" />
        </td>
    </tr>
    <tr>
        <td>
            Hello
        </td>
        <td>
            World
        </td>
        <td>
            !
        </td>
    </tr>
</table>

The <tr> elements all have border-top: dotted 1px black, this works fine apart from the central <td> element in the second <tr>.

This element has a double border and so appears as a solid line, removing the colspan fixes the issue.

I have tried applying border-collapse: collapse to the the table and this hasn't worked, I have tried adding content in the form of &nbsp; inside the first <td> instead of an image and this hasn't worked either.

Any ideas anyone?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Jake N
  • 10,535
  • 11
  • 66
  • 112

6 Answers6

25

Adding border-collapse: separate; to your table fixes the issue, see http://jsfiddle.net/quyMy/

I've added a dynamic test case to that fiddle. Click anywhere, and the visibility of the original/new table will toggle, allowing you to see the difference much easier.

Another way to get rid off the unexpected border is to add a plain <tr></tr> after the row containing <td colspan=3>.

egid
  • 685
  • 3
  • 14
Rob W
  • 341,306
  • 83
  • 791
  • 678
3

If you set the border on the table cells instead of the table rows, it will work.

I could only reproduce the bug in IE, but there are other known issues with the way that tables in IE render borders.

See this: http://jsfiddle.net/yePHg/19/

Victor
  • 4,989
  • 6
  • 31
  • 47
2

Add a row with a <hr /> between and then give the border to that hr

http://jsfiddle.net/Y5Gec/

yunzen
  • 32,854
  • 11
  • 73
  • 106
1

Try applying css display: block; on the tr:

    tr
    {
        border-top: 1px dotted #000;
        display: block;
    }
cristy
  • 317
  • 3
  • 9
0

I hit this same problem!

border-collapse: separate

worked great, but it also separated my borders (shocker, right?). I wanted a single dotted line. So here's what I did.

CSS:

td {
border-right: 1px dotted #bbb;
border-left: 1px dotted #bbb;
border-bottom: 1px dotted #bbb;
border-top: none;
padding: .5em;
}

th {
border-right: 1px dotted #bbb;
border-left: 1px dotted #bbb;
border-top: 1px dotted #bbb;
border-top: 1px solid #bbb;
padding: .5em;
}

HTML

<table border="1">
    <tr>
        <th colspan="5"> DRESSES &amp; TOPS </th>
    </tr>
    <tr>
        <td> size </td>
        <td> numerical </td>
        <td> bust </td>
        <td> waist </td>
        <td> hip< </td>
    </tr>
</table>
Barnee
  • 3,212
  • 8
  • 41
  • 53
renée
  • 9
  • 1
0

Try to add this css:

<style>
table, table * { border:0; padding:0; margin:0 }
table td { border-top:1px dotted #000 }
</style>
bogdanmogo
  • 123
  • 2
  • 9