8、CSS 表格样式

表格边框

如需在 CSS 中设置表格边框,请使用 border 属性。

下面的例子为 table、th 以及 td 设置了蓝色边框:

table, th, td
  {
  border: 1px solid blue;
  }

 

 

折叠边框

border-collapse 属性设置是否将表格边框折叠为单一边框:

table
  {
  border-collapse:collapse;
  }

table,th, td
  {
  border: 1px solid black;
  }

 

 

表格内边距

如需控制表格中内容与边框的距离,请为 td 和 th 元素设置 padding 属性:

td
  {
  padding:15px;
  }

 

 

表格文本对齐

text-align 和 vertical-align 属性设置表格中文本的对齐方式

text-align 属性设置水平对齐方式,比如左对齐、右对齐或者居中:

td
  {
  text-align:right;
  }

vertical-align 属性设置垂直对齐方式,比如顶部对齐、底部对齐或居中对齐:

td
  {
  height:50px;
  vertical-align:bottom;
  }

 

 

表格颜色

下面的例子设置边框的颜色,以及 th 元素的文本和背景颜色:

table, td, th
  {
  border:1px solid green;
  }

th
  {
  background-color:green;
  color:white;
  }

 

posted @ 2018-03-18 20:19  FullStack~ELF  阅读(174)  评论(0)    收藏  举报