久久久久久久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 選擇器的工具?)
主站蜘蛛池模板: 久久久久久电影 | 久久成人精品视频 | www.99精品| 精品国产乱码久久久久久88av | a视频在线观看 | 亚洲一区亚洲二区 | 成年无码av片在线 | 国产精品国产成人国产三级 | 欧美中文字幕一区二区三区亚洲 | 一级h片 | 欧美性区 | 91精品久久久久久久久久小网站 | 国产高清一区二区 | 午夜理伦三级理论三级在线观看 | 日韩视频 中文字幕 | jlzzjlzz国产精品久久 | 在线观看视频一区二区三区 | 一级毛片免费看 | 日韩成人影院 | 97视频成人 | 在线国产小视频 | 中文字幕日本一区二区 | 中文在线一区二区 | 久久99精品久久久久久琪琪 | 亚洲国产成人精品久久久国产成人一区 | 懂色av一区二区三区在线播放 | 影音先锋中文在线 | 久久综合九九 | 国产乱码精品一区二区三区av | 欧美中文字幕一区二区三区 | 日韩国产一区二区三区 | 精品九九久久 | 成人久久18免费网站麻豆 | 一级片网址 | 在线视频 欧美日韩 | 欧美日韩在线播放 | 日本色综合 | 精品日韩一区二区 | 久久一区精品 | 亚洲美女在线视频 | 国产免费观看一区 |