css漂亮的表格

0 css漂亮的表格

下面是一个简单的css表格,你可以根据你的需求进行修改:

html代码:

<table>
  <thead>
    <tr>
      <th>姓名</th>
      <th>年龄</th>
      <th>性别</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>小明</td>
      <td>20</td>
      <td>男</td>
    </tr>
    <tr>
      <td>小红</td>
      <td>22</td>
      <td>女</td>
    </tr>
    <tr>
      <td>小刚</td>
      <td>21</td>
      <td>男</td>
    </tr>
  </tbody>
</table>
CSS代码:
table {
  border-collapse: collapse;
  width: 100%;
  font-size: 14px;
  margin-bottom: 20px;
}

th, td {
  text-align: left;
  padding: 8px;
  border-bottom: 1px solid #ddd;
}

th {
  background-color: #f2f2f2;
  font-weight: bold;
}

tr:hover {
  background-color: #f5f5f5;
}
这个表格样式包含以下特点:
使用 border-collapse 属性合并单元格边框,使得表格边框更加整齐。
使用 width 属性设置表格宽度为100%。
使用 font-size 属性设置表格字体大小。
使用 margin-bottom 属性设置表格下方的间距。
使用 text-align 属性设置单元格中的文本居左对齐。
使用 padding 属性设置单元格内部的空白。
使用 border-bottom 属性设置单元格底部的边框。
使用 background-color 属性设置表头单元格的背景颜色。
使用 font-weight 属性设置表头单元格字体为粗体。
使用 tr:hover 选择器设置当鼠标悬停在单元格上时,单元格的背景颜色改变。
赞(0)
打赏 微信扫一扫微信 支付宝 QQ 扫码打赏
如若转载,请注明本文出自:https://www.guaitoo.com/show/236.html