久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何使用 nth-child 對具有行跨度的表格進行樣式設

How to use nth-child for styling with a table with rowspan?(如何使用 nth-child 對具有行跨度的表格進行樣式設置?)
本文介紹了如何使用 nth-child 對具有行跨度的表格進行樣式設置?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我有一個表,其中一行使用行跨度.所以,

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

<table>
 <tr>
  <td>...</td><td>...</td><td>...</td>
 </tr>
 <tr>
  <td rowspan="2">...</td><td>...</td><td>...</td>
 </tr>
 <tr>
              <td>...</td><td>...</td>
 </tr>
 <tr>
  <td>...</td><td>...</td><td>...</td>
 </tr>
</table>

我想使用 nth-child 偽類為每隔一行添加背景顏色,但是行跨度搞砸了;它將背景顏色添加到具有行跨度的行下方的行中,而實際上我希望它跳過該行并移至下一行.

I'd like to use the nth-child pseudo-class to add a background color to every other row, but the rowspan is messing it up; it adds the background color to the row below the row with the rowspan, when in fact I'd like it to skip that row, and move onto the next.

有沒有辦法讓 nth-child 做一些聰明的事情,或者在選擇器中使用 [rowspan] 來解決這個問題?所以在這種情況下,我希望背景顏色位于第 1 行和第 4 行,但之后位于第 6、8、10 行等等(因為這些都沒有行跨度)?這就像如果我看到一個行跨度,那么我希望 nth-child 將 1 添加到 n 然后繼續.

Is there a way to get nth-child to do something smart, or to use [rowspan] in the selector to get around this? So in this case, I'd like the background color to be on rows 1 and 4 but then after that on 6, 8, 10, and so on (since none of those have rowspans)? It's like if I see a rowspan, then I want nth-child to add 1 to n and then continue.

可能沒有解決方案,但我想我會問:-)

Probably no solution to this, but thought I'd ask :-)

推薦答案

不幸的是,單獨使用 :nth-child() 或單獨使用 CSS 選擇器無法做到這一點.這與 :nth-child() 的性質有關,它純粹基于作為其父元素的第 n 個子元素進行選擇,以及與 CSS 缺少父選擇器(只有在沒有的情況下才能選擇 trt 包含一個 td[rowspan],例如).

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 確實有 CSS 缺少的 :has() 選擇器,但是您可以將它與 :even 結合使用(而不是 :odd 因為它是 0-indexed 而不是 :nth-child() 的 1-index) 用于過濾作為 CSS 的替代方案:

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 預覽

這篇關于如何使用 nth-child 對具有行跨度的表格進行樣式設置?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Style every third element?(每隔三個元素設置樣式?)
Why shouldn#39;t I use ID selectors in CSS?(為什么我不應該在 CSS 中使用 ID 選擇器?)
What does img[class*=quot;alignquot;] mean in CSS?(CSS 中的 img[class*=“align] 是什么意思?)
CSS: Last element on line(CSS:最后一個元素)
How do I select every other div class element using just CSS (no js)(如何僅使用 CSS(無 js)選擇所有其他 div 類元素)
Tool for checking unused CSS selectors?(檢查未使用的 CSS 選擇器的工具?)
主站蜘蛛池模板: 国产目拍亚洲精品99久久精品 | 亚洲一区二区三区视频在线 | 久久久久亚洲av毛片大全 | 国产精品免费一区二区三区四区 | 性国产xxxx乳高跟 | 97精品国产| 欧美精品video| 久久88 | 久久久久国产精品一区二区 | 91亚洲国产成人精品一区二三 | 欧洲毛片 | 亚洲免费视频在线观看 | 亚洲444kkkk在线观看最新 | 国产精品视频久久久 | 一区精品国产欧美在线 | 午夜影院在线观看免费 | 色毛片 | 中文字幕第三页 | 俺去俺来也www色官网cms | 久久综合一区二区三区 | 久久久久91 | 国产一区二区毛片 | 国产精品亚洲精品 | 日韩精品久久一区二区三区 | 亚洲一区二区三区免费观看 | 欧美中文字幕在线观看 | 激情av在线 | 亚洲成人999 | 国产精品久久久久久久久久久久久久 | 成人免费网站在线 | 国产精产国品一二三产区视频 | 久久久久久一区 | 欧美视频免费在线观看 | 2019精品手机国产品在线 | 日本中出视频 | 欧美黄色一区 | 91色视频在线观看 | 亚洲国产视频一区 | 中文字幕一区二区在线观看 | www.天天操| 日韩一区二区三区在线视频 |