表格边框css

table标签默认是没有边框的,但是如果我们自己加上边框boder:1px solid black;只有整个表格最外面有边框,那么如何给表格添加样式使得整个表格的tr、td都具有边框呢:

 1 <style>
 2 table, th , td  {
 3   border: 1px solid grey;
 4   border-collapse: collapse;
 5   padding: 5px;
 6 }
 7 table tr:nth-child(odd)    {
 8   background-color: #f1f1f1;
 9 }
10 table tr:nth-child(even) {
11   background-color: #ffffff;
12 }
13 </style>

上面代码中最后还加上了CSS3 :nth-child() 选择器对奇、偶行采用不同的背景色,同时也可以采用公式table tr:(2n+1)使用。

posted @ 2015-12-08 01:39  纸鸢&红豆·绿豆  阅读(127)  评论(0编辑  收藏  举报