How to use nth-child for styling with a table with rowspan?

后端 未结 6 1991
盖世英雄少女心
盖世英雄少女心 2020-12-01 17:37

I have a table that has one row that uses rowspan. So,

6条回答
  •  心在旅途
    2020-12-01 18:34

    Unfortunately, there's no way to do this with :nth-child() alone, or by using CSS selectors alone for that matter. This has to do with the nature of :nth-child() which selects purely based on an element being the nth child of its parent, as well as with CSS's lack of a parent selector (you can't select a tr only if it doesn't contain a td[rowspan], for example).


    jQuery does have the :has() selector that CSS lacks, though, which you can use in conjunction with :even (not :odd as it's 0-indexed versus :nth-child()'s 1-index) for filtering as an alternative to CSS:

    $('tr:not(:has(td[rowspan])):even')
    

    jsFiddle preview

提交回复
热议问题
.........