CSS 表格属性可以帮助您极大地改善表格的外观。
表格边框
如需在 CSS 中设置表格边框,请使用 border 属性。如为 table、th 以及 td 设置蓝色边框:
table, th, td {border: 1px solid blue;}注释:本实例中的表格具有双线条边框。这是由于 table、th 以及 td 元素都有独立的边框。
table {border-collapse: collapse;} table,th, td {border: 1px solid black;}
table {width: 100%;} th {height:50px;}注释:本实例将表格宽度设置为 100%,同时将 th 元素的高度设置为 50px。
td {text-align: right;}vertical-align 属性设置垂直对齐方式,比如顶部对齐、底部对齐或居中对齐:
td {height: 50px; vertical-align: bottom;}
td {padding: 15px;}
table, td, th {border: 1px solid green;} th {background-color: green; color: white;}
<html> <head> <style type="text/css"> #customers { font-family: "Trebuchet MS", Arial, Helvetica, sans-serif; width: 100%; border-collapse: collapse; } #customers td, #customers th { font-size: 1em; border: 1px solid #98bf21; padding: 3px 7px 2px 7px; } #customers th { font-size: 1.1em; text-align: left; padding-top: 5px; padding-bottom: 4px; background-color: #A7C942; color: #ffffff; } #customers tr.alt td { color: #000000; background-color: #EAF2D3; } </style> </head> <body> <table id="customers"> <tr> <th>Company</th> <th>Contact</th> <th>Country</th> </tr> <tr> <td>Apple</td> <td>Steven Jobs</td> <td>USA</td> </tr> <tr class="alt"> <td>Baidu</td> <td>Li YanHong</td> <td>China</td> </tr> <tr> <td>Google</td> <td>Larry Page</td> <td>USA</td> </tr> <tr class="alt"> <td>Lenovo</td> <td>Liu Chuanzhi</td> <td>China</td> </tr> <tr> <td>Microsoft</td> <td>Bill Gates</td> <td>USA</td> </tr> <tr class="alt"> <td>Nokia</td> <td>Stephen Elop</td> <td>Finland</td> </tr> </table> </body> </html>
评论