2013-03-16 86 views
0

我有这样的样式表与CSS

<table> 
    <tr> 
     <td>Content</td>      
     <td>Content</td>      
     <td>Content</td>           
    </tr> 
    <tr> 
     <td>Content</td>      
     <td>Content</td>      
     <td>Content</td>           
    </tr> 
    <tr> 
     <td>Content</td>      
     <td>Content</td>      
     <td>Content</td>           
    </tr> 
</table> 

HTML表格现在我需要它的样式像这样...

enter image description here

我用CSS尝试过这样的:

table td { 
    padding: 20px 20px; 
    width: 33%; 
    vertical-align: top; 
    border-bottom: 1px dashed #b4b4b4; 
    border-right: 1px dashed #b4b4b4; 
} 

但不能得到我期待的结果。我不能在这个问题上使用内联样式。

希望有人会帮助我。

谢谢。

+0

另外尝试添加这个 - 'tr:最后一个孩子{border = bottom:none; ' }'但没有运气 – TNK 2013-03-16 13:14:37

回答

1

http://jsfiddle.net/pjLFY/

你几乎是正确的。

您需要设置的边界没有任何td的去年tr,但只设置是行的边界无法比拟的。

table tr:last-child td { 
    border-bottom: none; 
} 

table td:last-child { 
    border-right: none; 
} 
+0

感谢您的回复。 “最后一个孩子”在IE 7和8中不起作用,不是吗? – TNK 2013-03-16 13:22:40

+0

是的,':最后一个孩子'只支持IE9 +。 – Cristy 2013-03-16 14:08:55

1

你可以用:last-child来实现,所以 试试用这个。

table td:last-child 
{ 
    border-right:none; 
} 
table tr:last-child td 
{ 
    border-bottom:none; 
} 

JS Fiddle Demo

1

试试这个:

table td { 
    padding: 20px 20px; 
    width: 33%; 
    border-bottom: 1px dashed #b4b4b4; 
    border-right: 1px dashed #b4b4b4; 
    background: #FFFDDC; 
} 
table td:last-child { 
    border-right: 0; 
} 
table tr:last-child td { 
    border-bottom: 0; 
} 
1

如果你不想使用:last-child,你知道网页的背景颜色,你可以添加以下:

table { 
    border-collapse: collapse; 
    border: 1px solid white; 
} 
1

代替用none0覆盖,你可以使用:last-child:not这样的:

table td { 
    padding: 20px 20px; 
    width: 33%; 
    vertical-align: top; 
} 
table tr:not(:last-child) td { 
    border-bottom: 1px dashed #b4b4b4; 
} 
table td:not(:last-child) { 
    border-right: 1px dashed #b4b4b4;  
} 

参见jsFiddle

+0

感谢您的建议。 ':不'对我来说是全新的。 – TNK 2013-03-16 13:33:20

+1

@TNK查看关于':not' [here](https://developer.mozilla.org/en/docs/CSS/not)的文档。 – Antony 2013-03-16 13:34:59