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

CSS 最后一個奇怪的孩子?

CSS Last Odd Child?(CSS 最后一個奇怪的孩子?)
本文介紹了CSS 最后一個奇怪的孩子?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我有一個無序列表,它可以包含偶數或奇數個項目.如果 li 的數量是偶數,我正在尋找一種純 CSS 方法來從最后 2 個 li 標記中刪除邊框.:last-child 偽選擇器無論如何都會刪除最后一個.

I have an unordered list, which can contain either an even or odd number of items. I'm looking for a CSS-only way to remove the border from the last 2 li tags if the number of lis is even. The :last-child pseudo-selector removes the last one regardless.

li {
float: left;
border-bottom: 1px solid #000;
}

li:last-child{
border-bottom: none;
}

適用于奇數個 lis

+============================================+
+          1          |          2           +
+--------------------------------------------+
+          3          |                      +
+============================================+

但對于偶數,我需要刪除單元格 #3 的底部

+============================================+
+          1          |          2           +
+--------------------------------------------+
+          3          |          4           +
+---------------------                       +
+============================================+

所以我想我可以使用 li:nth-last-child() 但我無法弄清楚抓住最后一個奇數孩子的方程式應該是什么.

So I figured I could use li:nth-last-child() but I can't figure out what should be the equation to grab the last odd child.

這不是 2n+12n-1n-1 或任何我能想到的.請幫忙.

It's not 2n+1, 2n-1, n-1, or anything I can think of. Please help.

推薦答案

nth-last-child 從最后一個child倒數,所以要搶倒數第二個,表達式為:

nth-last-child counts backwards from the last child, so to grab the second to last, the expression is:

li:nth-last-child(2)

您可以組合偽選擇器,因此要選擇倒數第二個孩子,但只有當它是奇數時,使用:

You can combine pseudo-selectors, so to select the 2nd to last child, but only when it's odd, use:

li:nth-last-child(2):nth-child(odd) {border-bottom: none;}

所以,整個事情應該是:

And so, the whole thing should be:

li:last-child,
li:nth-last-child(2):nth-child(odd) {border-bottom: none;}

在回答@ithil 的問題時,這是我在 SASS 中的寫法:

In answer to @ithil's question, here's how I'd write it in SASS:

li
  &:last-child,
  &:nth-last-child(2):nth-child(odd)
    border-bottom: none

這并沒有那么簡單,因為選擇倒數第二個奇數孩子"總是需要兩步"選擇器.

It's not that much simpler, since the selection of the 'second-to-last odd child' is always going to require the 'two step' selector.

在回答@Caspert 的問題時,您可以通過對更多選擇器進行分組來對任意多個最后元素執行此操作(感覺應該有一些 xn+y 模式可以在不分組的情況下執行此操作,但是 AFAIU這些模式只是通過從最后一個元素倒數來工作).

In answer to @Caspert's question, you can do this for arbitrarily many last elements by grouping more selectors (there feels like there should be some xn+y pattern to do this without grouping, but AFAIU these patterns just work by counting backwards from the last element).

對于最后三個元素:

li:last-child,
li:nth-last-child(2):nth-child(odd),
li:nth-last-child(3):nth-child(odd) {border-bottom: none;}

這是一個像 SASS 這樣的東西可以幫助生成選擇器的地方.我會將其構建為占位符類,并用它擴展元素,并在變量中設置列數,如下所示:

This is a place where something like SASS can help, to generate the selectors for you. I would structure this as a placeholder class, and extend the element with it, and set the number of columns in a variable like this:

$number-of-columns: 3

%no-border-on-last-row
 @for $i from 1 through $number-of-columns
   &:nth-last-child($i):nth-child(odd)
     border-bottom: none

//Then, to use it in your layout, just extend:

.column-grid-list li
  @extend %no-border-on-last-row

這篇關于CSS 最后一個奇怪的孩子?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

CSS selector when :target empty(:target 為空時的 CSS 選擇器)
Does the CSS direct decendant (gt;) not have any value in selectivity?(CSS 直接后代 (gt;) 在選擇性方面沒有任何價值嗎?)
Using querySelectorAll(). Is the result returned by the method ordered?(使用 querySelectorAll().方法返回的結果是否有序?)
Safari bug :first-child doesn#39;t update display:block when items are removed with JS(Safari 錯誤:當使用 JS 刪除項目時,first-child 不更新 display:block)
nth-Child CSS selectors(nth-子 CSS 選擇器)
Using same ID for multiple HTML tags?(對多個 HTML 標簽使用相同的 ID?)
主站蜘蛛池模板: 99精品久久久久久中文字幕 | 国产精品美女久久久久久久网站 | 日韩av看片 | 天堂成人国产精品一区 | 精品久久久久一区二区国产 | 国产综合精品 | 九九国产 | 91精品国产91| 午夜在线小视频 | 亭亭五月激情 | 日韩免费在线 | 欧美日产国产成人免费图片 | www.激情.com| 午夜av一区二区 | 国产精品久久久久久一区二区三区 | 日韩一区三区 | 狠狠色综合网站久久久久久久 | 青青草视频网站 | 黄视频网站在线 | www亚洲免费国内精品 | 一级免费毛片 | 精品久久国产 | 精品国产一区二区国模嫣然 | 青青草av | 嫩草影院黄 | 国产一区二区在线免费观看 | 狠狠干影院 | 精品久久一区二区 | 精品欧美一区二区三区免费观看 | 一区二区成人 | 麻豆精品久久 | av在线成人 | 黑人精品xxx一区一二区 | 国内精品视频在线观看 | 精品伊人久久 | 91精品国产欧美一区二区成人 | 天天躁日日躁aaaa视频 | 久久一区二区免费视频 | 亚洲精品视频在线 | 黄色一级电影免费观看 | 在线播放精品视频 |