突出显示表列组

时间:2016-05-31 14:58:43

标签: css html5 css3 html-table datagridviewcolumn

我有一个列,我需要突出显示相邻的列。

对于以下example fiddle



<table border="1" style="width:100%;">
  <tbody>
    <tr>
      <th>Number</th>
      <th>First Name</th>
      <th>Last Name</th>
      <th>Points</th>
    </tr>
    <tr>
      <td>1</td>
      <td>Eve</td>
      <td>Jackson</td>
      <td>94</td>
    </tr>
    <tr>
      <td>2</td>
      <td>John</td>
      <td>Doe</td>
      <td>80</td>
    </tr>
    <tr>
      <td>3</td>
      <td>Adam</td>
      <td>Johnson</td>
      <td>67</td>
    </tr>
    <tr>
      <td>4</td>
      <td>Jill</td>
      <td>Smith</td>
      <td>50</td>
    </tr>
  </tbody>
</table>
&#13;
&#13;
&#13;

我需要在下面的一对列

周围显示额外边框
  • NumberFirst Name
  • Last NamePoints

我该怎么做?

任何建议,善良的人?

2 个答案:

答案 0 :(得分:1)

这可以通过以下方式完成:nth-​​child

&#13;
&#13;
<style type="text/css" scoped>
   table td:nth-child(odd) {
       border-left:red 1px solid;
   }
   table td:nth-child(even) {
       border-right:red 1px solid;
   }
</style>

<table border="1" style="width:100%;">
  <tbody>
    <tr>
      <th>Number</th>
      <th>First Name</th>
      <th>Last Name</th>
      <th>Points</th>
    </tr>
    <tr>
      <td>1</td>
      <td>Eve</td>
      <td>Jackson</td>
      <td>94</td>
    </tr>
    <tr>
      <td>2</td>
      <td>John</td>
      <td>Doe</td>
      <td>80</td>
    </tr>
    <tr>
      <td>3</td>
      <td>Adam</td>
      <td>Johnson</td>
      <td>67</td>
    </tr>
    <tr>
      <td>4</td>
      <td>Jill</td>
      <td>Smith</td>
      <td>50</td>
    </tr>
  </tbody>
</table>
&#13;
&#13;
&#13;

答案 1 :(得分:1)

您可以使用DELETE选择器实现此目的。

&#13;
&#13;
:nth-child
&#13;
tr:first-child th:nth-child(1), tr:first-child th:nth-child(2){
   border: 1px solid red;
   border-bottom: 0;
}

tr td:nth-child(1), tr td:nth-child(2){
   border-left: 1px solid red;
   border-right: 1px solid red;
}

tr:last-child td:nth-child(1), tr:last-child td:nth-child(2){
   border-bottom: 1px solid red;
}

tr:first-child th:nth-child(3), tr:first-child th:nth-child(4){
   border: 1px solid green;
   border-bottom: 0;
}

tr td:nth-child(3), tr td:nth-child(4){
   border-left: 1px solid green;
   border-right: 1px solid green;
}

tr:last-child td:nth-child(3), tr:last-child td:nth-child(4){
   border-bottom: 1px solid green;
}
&#13;
&#13;
&#13;