2013-12-10 96 views
1

我正在構建一個動態表格。表格邊框間距:表格沒有空間

每個單元格都有灰色的背景色,我希望每個單元格之間有一個空白區域(垂直和水平)。

所以我使用的CSS屬性

table { 
border-spacing:10px; 
} 
td { 
background-color:grey; 
} 

它運作良好,除了事實,這白色的空間不僅是細胞之間;它實際上是在每個單元格周圍,包括位於表格邊緣的單元格。

這意味着桌子周圍有白色空間。

有沒有辦法地說:「把例外的單元格邊框之間的空間,如果該邊界在桌子上的邊緣」

注:這是一個動態表,所以我想避免爲「內部」單元提供專用的CSS類。

回答

0

您可能能夠才達到你想要

設計
table { 
    border-collapse:collapse; 
} 
td { 
    background-color:grey; 
    border:10px solid red; /*assuming red is the color of the background to make it look transparent*/ 
} 
tr:first-child td{border-top:0} 
tr:last-child td{border-bottom:0} 
td:first-child{border-left:0;} 
td:last-child{border-right:0;} 

演示在​​

+0

是的人,你是唯一! – Ren

0

有關,如果你在你的CSS使用

:not(:first-child):not(:last-child) 

什麼? 這是一個解決方案?

會是什麼樣子

table:not(:first-child):not(:last-child) 
{ 
    border-spacing:10px; 
} 

您可以使用多個參數分開間距:

border-spacing: 10px 10px; 

border-spacing: 5px 10px 5px 10px; 
+0

我相信邊界間距是在桌子上,而不是單元格。 – Leeish