How to select first and last TD in a row?

前端 未结 5 1408
谎友^
谎友^ 2020-11-30 23:01

How can you select the first and the last TD in a row?

tr > td[0],
tr > td[-1] {
/* styles */
}
5条回答
  •  借酒劲吻你
    2020-11-30 23:05

    You can use the following snippet:

      tr td:first-child {text-decoration: underline;}
      tr td:last-child {color: red;}
    

    Using the following pseudo classes:

    :first-child means "select this element if it is the first child of its parent".

    :last-child means "select this element if it is the last child of its parent".

    Only element nodes (HTML tags) are affected, these pseudo-classes ignore text nodes.

提交回复
热议问题