从某些行条带化的Bootstrap

时间:2017-09-20 11:06:37

标签: css twitter-bootstrap-3

我希望我的表从第7行开始。

这不起作用:

.table-striped > tbody > tr:nth-child(7n)

2 个答案:

答案 0 :(得分:1)

你需要使用n + 7来做到这一点。

.table-striped > tbody > tr:nth-child(n+7) td

答案 1 :(得分:1)

你需要这个

.table-striped tbody tr:nth-of-type(2n+7) td {
  background: /* your color here */;
}

Codepen Demo



td {
  border:1px solid grey;
  padding:1em;
}

.table-striped tbody tr:nth-of-type(odd) {
  background:none !important;
}

.table-striped tbody tr:nth-of-type(2n+7) {
  background:lightgrey !important;
}

/* note !important is only used here for demo purposes. */

/* This seesm to be because the CSS is applied in the wrong order in Snippets */

/* See the Codepen Demo for use without !important */

<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-beta/css/bootstrap.min.css" rel="stylesheet" />
<table class="table table-striped">
  <tbody>
    <tr>
      <td></td>
      <td></td>
      <td></td>
    </tr>
    <tr>
      <td></td>
      <td></td>
      <td></td>
    </tr>
    <tr>
      <td></td>
      <td></td>
      <td></td>
    </tr>
    <tr>
      <td></td>
      <td></td>
      <td></td>
    </tr>
    <tr>
      <td></td>
      <td></td>
      <td></td>
    </tr>
    <tr>
      <td></td>
      <td></td>
      <td></td>
    </tr>
    <tr>
      <td></td>
      <td></td>
      <td></td>
    </tr>
    <tr>
      <td></td>
      <td></td>
      <td></td>
    </tr>
    <tr>
      <td></td>
      <td></td>
      <td></td>
    </tr>
    <tr>
      <td></td>
      <td></td>
      <td></td>
    </tr>
    <tr>
      <td></td>
      <td></td>
      <td></td>
    </tr>
    <tr>
      <td></td>
      <td></td>
      <td></td>
    </tr>
    <tr>
      <td></td>
      <td></td>
      <td></td>
    </tr>
    <tr>
      <td></td>
      <td></td>
      <td></td>
    </tr>
    <tr>
      <td></td>
      <td></td>
      <td></td>
    </tr>
  </tbody>
</table>
&#13;
&#13;
&#13;