pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

Zebra 使用 CSS3 對帶有隱藏行的表進行條帶化處理

Zebra striping a table with hidden rows using CSS3?(Zebra 使用 CSS3 對帶有隱藏行的表進行條帶化處理?)
本文介紹了Zebra 使用 CSS3 對帶有隱藏行的表進行條帶化處理?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我有一張桌子

<table id="mytable">
    <tr style="display: none;"><td>&nbsp;</td></tr>
    <tr><td>&nbsp;</td></tr>
    <tr style="display: none;"><td>&nbsp;</td></tr>
    <tr><td>&nbsp;</td></tr>
    <tr><td>&nbsp;</td></tr>
    <tr><td>&nbsp;</td></tr>
 </table>

我正在嘗試將表格條帶化設置為使用第 n 個子選擇器,但似乎無法破解它.

I'm trying to set the table striping to use nth-child selectors but just can't seem to crack it.

 table #mytable tr[@display=block]:nth-child(odd) { 
      background-color:  #000;  
 }
 table #mytable tr[@display=block]:nth-child(odd) { 
      background-color:  #FFF;
 }

我很確定我已經接近了......似乎無法破解它.

I'm pretty sure I'm close ... can't quite seem to crack it.

有人提供線索嗎?

推薦答案

這是你將要得到的最接近的.請注意,您不能讓 nth-child 只計算顯示的行數;nth-child 無論如何都會采用第 n 個子元素,而不是匹配給定選擇器的 nth 子元素.如果您希望丟失某些行而不影響斑馬條紋,則必須通過 DOM 或服務器端將它們從表中完全刪除.

Here's as close as you're going to get. Note that you can't make the nth-child count only displayed rows; nth-child will take the nth child element no matter what, not the nth child that matches a given selector. If you want some rows to be missing and not affect the zebra-striping, you will have to remove them from the table entirely, either through the DOM or on the server side.

<!DOCTYPE html>
<style>
#mytable tr:nth-child(odd) { 
      background-color:  #000;  
 }
#mytable tr:nth-child(even) { 
      background-color:  #FFF;
 }
</style>
<table id="mytable">
    <tr><td>&nbsp;</td></tr>
    <tr><td>&nbsp;</td></tr>
    <tr><td>&nbsp;</td></tr>
    <tr><td>&nbsp;</td></tr>
    <tr><td>&nbsp;</td></tr>
    <tr><td>&nbsp;</td></tr>
 </table>

以下是我所做的修復:

 table #mytable tr[@display=block]:nth-child(odd) { 
      background-color:  #000;  
 }

無需為基于 id 的選擇器指定祖先選擇器;只有一個元素會匹配 #table,所以你只是通過添加 table 來添加額外的代碼.

There's no need to specify an ancestor selector for an id based selector; there is only ever one element that will match #table, so you're just adding extra code by adding the table in.

 #mytable tr[@display=block]:nth-child(odd) { 
      background-color:  #000;  
 }

現在,[@display=block] 將匹配屬性 display 設置為 block 的元素,例如 .Display 不是有效的 HTML 屬性;你似乎想要做的是讓選擇器匹配元素的樣式,但你不能在 CSS 中做到這一點,因為瀏覽器需要應用 CSS 中的樣式才能弄清楚,這它在應用此選擇器時正在執行中.因此,您將無法選擇是否顯示表格行.由于 nth-child 無論如何只能取第 nth 個孩子,而不是帶有某些屬性的第 nth 個孩子,我們將不得不放棄這部分CSS.還有nth-of-type,它選擇相同元素類型的第n個子元素,但你只能這樣做.

Now, [@display=block] would match elements which had an attribute display set to block, such as <tr display=block>. Display isn't a valid HTML attribute; what you seem to be trying to do is to have the selector match on the style of the element, but you can't do that in CSS, since the browser needs to apply the styles from the CSS before it can figure that out, which it's in the process of doing when it's applying this selector. So, you won't be able to select on whether table rows are displayed. Since nth-child can only take the nth child no matter what, not nth with some attribute, we're going to have to give up on this part of the CSS. There is also nth-of-type, which selects the nth child of the same element type, but that's all you can do.

 #mytable tr:nth-child(odd) { 
      background-color:  #000;  
 }

你有它.

這篇關于Zebra 使用 CSS3 對帶有隱藏行的表進行條帶化處理?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 選擇器的工具?)
主站蜘蛛池模板: 仿真茅草_人造茅草瓦价格_仿真茅草厂家_仿真茅草供应-深圳市科佰工贸有限公司 | 酵素生产厂家_酵素OEM_酵素加盟_酵素ODM_酵素原料厂家_厦门益力康 | 苏州同创电子有限公司 - 四探针测试仪源头厂家 | 干洗店加盟_洗衣店加盟_干洗店设备-伊蔻干洗「武汉总部」 | 100国际学校招生 - 专业国际学校择校升学规划| BOE画框屏-触摸一体机-触控查询一体机-触摸屏一体机价格-厂家直销-触发电子 | loft装修,上海嘉定酒店式公寓装修公司—曼城装饰 | 999范文网_优质范文下载写作帮手| 手板_手板模型制作_cnc手板加工厂-东莞天泓| 中医治疗皮肤病_潍坊银康医院「山东」重症皮肤病救治平台 | 「安徽双凯」自动售货机-无人售货机-成人用品-自动饮料食品零食售货机 | 洁净棚-洁净工作棚-无菌室-净化工程公司_北京卫护科技有限公司 | 游泳池设备安装工程_恒温泳池设备_儿童游泳池设备厂家_游泳池水处理设备-东莞市君达泳池设备有限公司 | 精雕机-火花机-精雕机 cnc-高速精雕机-电火花机-广东鼎拓机械科技有限公司 | 上海瑶恒实业有限公司|消防泵泵|离心泵|官网| 电地暖-电采暖-发热膜-石墨烯电热膜品牌加盟-暖季地暖厂家 | 安徽免检低氮锅炉_合肥燃油锅炉_安徽蒸汽发生器_合肥燃气锅炉-合肥扬诺锅炉有限公司 | 滁州高低温冲击试验箱厂家_安徽高低温试验箱价格|安徽希尔伯特 | 安平县鑫川金属丝网制品有限公司,声屏障,高速声屏障,百叶孔声屏障,大弧形声屏障,凹凸穿孔声屏障,铁路声屏障,顶部弧形声屏障,玻璃钢吸音板 | 黄石妇科医院_黄石东方女子医院_黄石东方妇产医院怎么样 | 吨袋包装机|吨包秤|吨包机|集装袋包装机-烟台华恩科技 | 数码管_LED贴片灯_LED数码管厂家-无锡市冠卓电子科技有限公司 | 神超官网_焊接圆锯片_高速钢锯片_硬质合金锯片_浙江神超锯业制造有限公司 | 河南生物显微镜,全自动冰冻切片机-河南荣程联合科技有限公司 | Brotu | 关注AI,Web3.0,VR/AR,GPT,元宇宙区块链数字产业 | 昆明网络公司|云南网络公司|昆明网站建设公司|昆明网页设计|云南网站制作|新媒体运营公司|APP开发|小程序研发|尽在昆明奥远科技有限公司 | 辐射仪|辐射检测仪|辐射巡测仪|个人剂量报警仪|表面污染检测仪|辐射报警仪|辐射防护网 | 蓝米云-专注于高性价比香港/美国VPS云服务器及海外公益型免费虚拟主机 | 浙江自考_浙江自学考试网| UV固化机_UVLED光固化机_UV干燥机生产厂家-上海冠顶公司专业生产UV固化机设备 | 湖南自考_湖南自学考试网 | 禹城彩钢厂_钢结构板房_彩钢复合板-禹城泰瑞彩钢复合板加工厂 | 北京银联移动POS机办理_收银POS机_智能pos机_刷卡机_收银系统_个人POS机-谷骐科技【官网】 | 河北凯普威医疗器材有限公司,高档轮椅系列,推车系列,座厕椅系列,协步椅系列,拐扙系列,卫浴系列 | 烽火安全网_加密软件、神盾软件官网 | 天一线缆邯郸有限公司_煤矿用电缆厂家_矿用光缆厂家_矿用控制电缆_矿用通信电缆-天一线缆邯郸有限公司 | ET3000双钳形接地电阻测试仪_ZSR10A直流_SXJS-IV智能_SX-9000全自动油介质损耗测试仪-上海康登 | 转子泵_凸轮泵_凸轮转子泵厂家-青岛罗德通用机械设备有限公司 | 压力控制器,差压控制器,温度控制器,防爆压力控制器,防爆温度控制器,防爆差压控制器-常州天利智能控制股份有限公司 | 密集柜_档案密集柜_智能密集架_密集柜厂家_密集架价格-智英伟业 密集架-密集柜厂家-智能档案密集架-自动选层柜订做-河北风顺金属制品有限公司 | Safety light curtain|Belt Sway Switches|Pull Rope Switch|ultrasonic flaw detector-Shandong Zhuoxin Machinery Co., Ltd |