如何在表格上设置边框

时间:2016-09-11 17:59:48

标签: html css html-table css-tables

假设我有一个包含大量数据的table元素。



table {
  background-color: skyblue;
  width: 100%;
  margin: auto;
  text-align: center;
}

<table>
  <tbody>
    <tr>
      <td>My Name</td>
      <td>My Name</td>
      <td>My Name</td>
      <td>My Name</td>
      <td>My Name</td>
      <td>My Name</td>
      <td>My Name</td>
      <td>My Name</td>
    </tr>
    <tr>
      <td>My Name</td>
      <td>My Name</td>
      <td>My Name</td>
      <td>My Name</td>
      <td>My Name</td>
      <td>My Name</td>
      <td>My Name</td>
      <td>My Name</td>
    </tr>
    <tr>
      <td>My Name</td>
      <td>My Name</td>
      <td>My Name</td>
      <td>My Name</td>
      <td>My Name</td>
      <td>My Name</td>
      <td>My Name</td>
      <td>My Name</td>
    </tr>
    <tr>
      <td>My Name</td>
      <td>My Name</td>
      <td>My Name</td>
      <td>My Name</td>
      <td>My Name</td>
      <td>My Name</td>
      <td>My Name</td>
      <td>My Name</td>
    </tr>
    <tr>
      <td>My Name</td>
      <td>My Name</td>
      <td>My Name</td>
      <td>My Name</td>
      <td>My Name</td>
      <td>My Name</td>
      <td>My Name</td>
      <td>My Name</td>
    </tr>
    <tr>
      <td>My Name</td>
      <td>My Name</td>
      <td>My Name</td>
      <td>My Name</td>
      <td>My Name</td>
      <td>My Name</td>
      <td>My Name</td>
      <td>My Name</td>
    </tr>
  </tbody>
</table>
&#13;
&#13;
&#13;

在每个偶数border-style: dashed; border-color: black; border-size: 3px;上设置td边框的最佳方法是什么。

请解释一下。

1 个答案:

答案 0 :(得分:6)

你可以尝试:

td:nth-child(even) {
   border-style: dashed; 
   border-color: black; 
   border-size: 3px;
}