开发者

Make several cells of an HTML table appear joined without being so

开发者 https://www.devze.com 2023-03-19 17:58 出处:网络
I have a table in html and I need to make several cells appear joined, without being actually joined. This because each cell must have a different background.

I have a table in html and I need to make several cells appear joined, without being actually joined. This because each cell must have a different background.

So I need to take away the right border from the left most cell; take away the left border from the right most cells; take away both border from the central cells.

Here is an example where I have a table with two rows, and 7 cells. In the second row, the cells should appear as being only 2 cells. One spanning 5 columns and one spanning 7.

<table>
<tr>
<td>foo</t开发者_Python百科d>
<td>foo</td>
<td>foo</td>
<td>foo</td>
<td>foo</td>
<td>foo</td>
<td>foo</td>
</tr>
<tr>
<td style="background-color:white; border-right: blank; border-left: solid;"  >foo</td>
<td style="background-color:green; border-right: blank; border-left: blank;"  ></td>
<td style="background-color:black; border-right: blank; border-left: blank;"  ></td>
<td style="background-color:yellow; border-right: blank; border-left: blank;"  ></td>
<td style="background-color:blue; border-right: solid; border-left: blank;"  ></td>

<td style="background-color:red; border-right: blank; border-left: solid;"  >foo</td>
<td style="background-color:pink; border-right: solid; border-left: blank;"  ></td>

</tr>
</table>

But then this is still not enough because there is still some background of the table that is shown between the cells. How do I take of that?


Give your table a class

<table class="myTable">
    <!-- Your Rows/Cells -->
</table>

Then with CSS do the following:

.myTable { 
    border: none;
    border-collapse: collapse;
    border-spacing: 0;
    margin: 0; 
    padding: 0; 
}

Also border:blank is incorrect, use border:none instead.


<style type='text/css'>
#left{
border-left:none;
}
#right{
border-right:none;
}
#both{
border-left:none;
border-right:none;
}
</style>

include these css ids in <td> elements of table. example: <table border=1> <tr> <td>1111</td> <td id='right'>2222</td> <td id='both'>3333</td> <td id='left'>4444</td> </tr> </table>


<td colspan="5" style="background-color:white; border-right: none; border-left: solid;">foo</td>
<td colspan="2"  style="background-color:red; border-right: solid; border-left: none;">foo</td>

Demo »

0

精彩评论

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

关注公众号