2017-09-05 19 views
0

我有以下css來獲得最後四個CSS選擇過去四年,如果最後一個元素是四個多,如果3的倍數的最後3

:nth-last-child(-n+4){border-bottom: none;} 

,並返回我這樣的結果:

enter image description here

在此,所有過去的四個孩子沒有邊框底部

但是,如果最後一項是3的倍數,它涉及到以前行。

enter image description here

我需要的是:

  1. 當最後一個項目是3的倍數,選擇只有最後3 enter image description here
  2. 當最後一個項目是2的倍數,只選擇最後2 enter image description here

此外,這需要在純粹的CSS。有人知道如何做到這一點?

回答

1

這將需要一些相當令人費解的選擇不是不像那些發現here,但它可以做到:

:first-child:nth-last-child(4n) ~ :nth-last-child(-n+4), 
:first-child:nth-last-child(4n+3) ~ :nth-last-child(-n+3), 
:first-child:nth-last-child(4n+2) ~ :nth-last-child(-n+2) { 
    border-bottom: none; 
} 
0

而不是使用邊框底部,

,我認爲你應該改變邊境之上,它是適合你的情況。

+1

不,這不是 - 如果底部邊框改爲頂部邊框,就沒有下邊框第二行最後一行沒有任何元素的元素。 – BoltClock

相關問題