4

[CSS] Select First Row of Table

 2 years ago
source link: http://siongui.github.io/2017/04/10/css-select-first-row-of-table/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

[CSS] Select First Row of Table

April 10, 2017

See the demo below. The first row is selected and styled.

(1,1) (1,2) (1,3) (1,4) (2,1) (2,2) (2,3) (2,4) (3,1) (3,2) (3,3) (3,4)

HTML:

<table class="first-row">
 <tbody>
  <tr>
    <td>(1,1)</td>
    <td>(1,2)</td>
    <td>(1,3)</td>
    <td>(1,4)</td>
  </tr>
  <tr>
    <td>(2,1)</td>
    <td>(2,2)</td>
    <td>(2,3)</td>
    <td>(2,4)</td>
  </tr>
  <tr>
    <td>(3,1)</td>
    <td>(3,2)</td>
    <td>(3,3)</td>
    <td>(3,4)</td>
  </tr>
 </tbody>
</table>

CSS:

table.first-row > tbody > tr:nth-of-type(1) {
  font-size: larger;
  color: red;
}

We use nth-of-type CSS selector to select the first tr of the table. If you want to select n-th row, change the number from 1 to n.

You may also be interested in [CSS] Select First Column of Table


Tested on: Chromium Version 56.0.2924.76 Built on Ubuntu , running on Ubuntu 16.10 (64-bit)


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK