如果没有,则以不同方式设置表格的第一列的样式

时间:2016-10-31 19:59:38

标签: html css

这就是我想要实现的目标:

enter image description here

这是我试图设计的标记:

  <h2>Table with no header</h2>
  <table>
    <tbody>
      <tr>
        <td>First column - bold</td>
        <td>Second column</td>
      </tr>
      <tr>
        <td>First column - bold</td>
        <td>Second column</td>
      </tr>
    </tbody>
  </table>

  <h2>Table with a header</h2>
  <table>
    <thead>
      <tr>
        <th>Header</th>
        <th>Header</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>First column - not bold</td>
        <td>Second column</td>
      </tr>
      <tr>
        <td>First column - not bold</td>
        <td>Second column</td>
      </tr>
    </tbody>
  </table>

关于如何达到预期结果的任何想法?

2 个答案:

答案 0 :(得分:3)

这样做,您使用直接子选择器var userInputDate; var matchingItems = _.takeWhile(items, {'startDate': userInputDate}); // matchingItems is an array of all items with the same startDate >first-child

:not()

样品

&#13;
&#13;
table > *:first-child:not(thead) td:first-child {
  font-weight: bold;
}
&#13;
table > *:first-child:not(thead) td:first-child {
  font-weight: bold;
}
&#13;
&#13;
&#13;

答案 1 :(得分:2)

我已经设法使用以下CSS实现了所需的外观:

  td:first-child {
    font-weight: bold;
  }
  thead + tbody td:first-child {
    font-weight: lighter;
  }