开发者

Double dotted border while using colspan

开发者 https://www.devze.com 2023-04-12 09:35 出处:网络
I have what seems like a simple problem, but searching the net hasn\'t yielded any results. I have a table

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 &开发者_如何学运维lt;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?


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>.


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/


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

http://jsfiddle.net/Y5Gec/


Try applying css display: block; on the tr:

    tr
    {
        border-top: 1px dotted #000;
        display: block;
    }


Try to add this css:

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


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>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号