[英]How to select all children except first and last with CSS selectors
除了第一個和最后一個之外,我如何選擇表格中的所有孩子? 我試過這個,但它最終選擇了所有不是第一個的孩子和所有不是最后的孩子,最終成為所有孩子:
table.programs tr td:not(:first-child), table.programs tr td:not(:last-child) {
}
我想要所有既不是第一個也不是最后一個的孩子。 我怎樣才能做到這一點?
使用兩個:not()
選擇器組合,從而引用匹配它們兩個的元素,即不匹配用作:not()
操作數的選擇器的元素:
table.programs td:not(:first-child):not(:last-child)
jQuery 解決方案很好,但如果你想用純 CSS 來做,我建議你將規則應用於整個表格,然后為第一個和最后一個孩子重置它們。 IE:
table.programs tr td {
/* your rules here */
}
table.programs tr:first-child td:first-child,
table.programs tr:last-child td:last-child {
/* reset your rules here */
}
我認為這應該適合你:
table.programs tr td:not(:first-child,:last-child)
像這樣。
li:nth-child(n+2):nth-last-child(n+2) { background: red; }
滿足您的要求
table.programs tr td:nth-child(n+2):nth-last-child(n+2) { /* Your Style */ }
它以這種方式工作
table.programs tr td:nth-child(1n+2):not(:last-child)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.