| CSS 表格 使用 CSS 可以极大地改善 HTML 表格的外观: 表格边框| Company |  |  |  |  |  |  | No. 699, Wangshang Road, Binjiang  District |  |  |  |  | 1 Infinite Loop Cupertino, CA 95014 |  |  |  |  | Lixiang guoji dasha,No 58, beisihuanxilu |  |  |  |  | One Canon Plaza Lake Success, NY 11042 |  |  |  |  | 1600 Amphitheatre Parkway Mountain View,  CA 94043 |  |  |  |  | Putian Huawei Base, Longgang District |  |  |  |  | 15700 NE 39th St Redmond, WA 98052 |  |  |  |  | P.O. Box 226, FIN-00045 Nokia Group |  |  |  |  |  |  |  |  |  | Tencent Building, High-tech Park, Nanshan  District |  | 
 如需在 CSS 中设置表格边框,请使用 border 属性。 下例为 <table>、<th> 和 <td> 元素规定了黑色边框: 实例table, th, td {  border: 1px solid black;}| Firstname | Lastname |  | Bill | Gates |  | Steve | Jobs | 
 
 注意:上例中的表格拥有双边框。这是因为 table 和 <th> 和 <td> 元素都有单独的边框。全宽表格 在某些情况下,上表似乎很小。如果您需要一个可以覆盖整个屏幕(全宽)的表格,请为<table> 元素添加 width:100%:实例table {  width: 100%;} 双边框
 请注意上面的表格有双边框。这是因为表格和 th、td 元素都有单独的边框。 如需删除双边框,请看下面的例子。合并表格边框 border-collapse 属性设置是否将表格边框折叠为单一边框:实例table {  border-collapse: collapse;} table, th, td {  border: 1px solid black;} 
 如果只希望表格周围有边框,则仅需为 <table> 指定 border 属性: 实例table {  border: 1px solid black;}| Firstname | Lastname |  | Bill | Gates |  | Steve | Jobs | 
 表格宽度和高度
 表格的宽度和高度由 width 和 height 属性定义。 下例将表的宽度设置为 100%,将 <th> 元素的高度设置为 50px:实例table {  width: 100%;} th {  height: 50px;} 
 要创建仅占页面一半的表,请使用 width: 50%:实例table {  width: 50%;} th {  height: 70px;} 水平对齐
 text-align 属性设置 <th> 或 <td> 中内容的水平对齐方式(左、右或居中)。 默认情况下,<th> 元素的内容居中对齐,而 <td> 元素的内容左对齐。 要使 <td> 元素的内容也居中对齐,请使用 text-align: center:实例th {  text-align: center;} 
 下例使 <th> 元素中的文本左对齐:实例th {  text-align: left;} 垂直对齐
 vertical-align 属性设置 <th> 或 <td> 中内容的垂直对齐方式(上、下或居中)。 默认情况下,表中内容的垂直对齐是居中(<th>和 <td> 元素都是)。 下例将 <td> 元素的垂直文本对齐方式设置为下对齐:实例td {  height: 50px;  vertical-align: bottom;} 表格内边距
 如需控制边框和表格内容之间的间距,请在<td> 和<th> 元素上使用 padding 属性:实例th, td {  padding: 15px;  text-align: left;} 水平分隔线
 向 <th> 和 <td> 添加 border-bottom 属性,以实现水平分隔线:实例th, td {  border-bottom: 1px solid #ddd;} 可悬停表格
 在 <tr> 元素上使用 :hover 选择器,以突出显示鼠标悬停时的表格行:实例tr:hover {background-color: #f5f5f5;} 条状表格
 为了实现斑马纹表格效果,请使用 nth-child() 选择器,并为所有偶数(或奇数)表行添加 background-color:实例tr:nth-child(even) {background-color: #f2f2f2;} 表格颜色
 下例指定了 <th> 元素的背景颜色和文本颜色:实例th {  background-color: #4CAF50;  color: white;} 响应式表格
 如果屏幕太小而无法显示全部内容,则响应式表格会显示水平滚动条: 在 <table> 元素周围添加带有 overflow-x:auto 的容器元素(例如 <div>),以实现响应式效果:实例<div style="overflow-x:auto;"> <table>... table content ...</table> </div> 
 注释:在 OS X Lion(在 Mac 上)中,滚动条默认情况下是隐藏的,并且仅在使用时显示(即使设置了"overflow:scroll")。CSS表格属性   
 |