简体   繁体   中英

HTML table cells not properly aligned

I have the following HTML table:

<table style="width: 100%;">
<tr>
    <td class="title_bar_left_border"></td>
    <td class="title_bar_middle"></td>
    <td class="title_bar_right_border"></td>
</tr>
</table>

With the following css rules:

.title_bar_left_border
{
    BACKGROUND-IMAGE: url(tray_left.gif);
    WIDTH:  3px;
    HEIGHT: 24px;
}

.title_bar_right_border
{
    BACKGROUND-IMAGE: url(tray_right.gif);
    WIDTH:  3px;
    HEIGHT: 24px;
}

.title_bar_middle
{
    BACKGROUND-IMAGE: url(tray_middle.gif);
    WIDTH: 100%;
    BACKGROUND-REPEAT: repeat-x;
    HEIGHT: 24px;
}

Any idea why this is the result?

替代文字

Instead of getting a nice table header with rounded corners you get this weird gap between the cells. Where are the gaps coming from? Besides fixing this ugly issue, I would like to understand the rationale as to why all browsers render the HTML this way.

Those bars are cell spacing and padding.

You need to set the background of the division to the color of the gif files. That white space is the padding around the cells.

You can also set cellpadding='0' and cellspacing='0' in the table definition. The default values are 1 and 2 respectively. I'd recommend against it, though, as it might cause issues with the data bearing rows.

You see the default spacing. Fix:

table
{
    border-collapse:  collapse;
    border-spacing:   0;
}
table{border-collapse:collapse;}

需要删除表格的边框...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM