我正在尋找只有CSS(無JS)的方式來忽略第n個孩子計數中的隱藏元素。這可能嗎?選擇第n個孩子跳過隱藏的元素
我有了這個HTML:
<div class="gallery-item"><img src="http://placehold.it/150x150"></div>
<div class="gallery-item"><img src="http://placehold.it/150x150"></div>
<div class="gallery-item empty"></div>
<div class="gallery-item"><img src="http://placehold.it/150x150"></div>
<div class="gallery-item empty"></div>
<div class="gallery-item"><img src="http://placehold.it/150x150"></div>
<div class="gallery-item"><img src="http://placehold.it/150x150"></div>
我努力的目標每秒庫項目,是不是空的,但是這不是工作:
.gallery-item:not(.empty):nth-child(2n) {}
我不想使用JS,因爲這是一個複雜的網站,有很多斷點,我不想爲這些基本的東西添加onresize監聽器。
據我所知,這是不可能的CSS,因爲'nth-child(2n)'會指向每個第二個孩子,如果它也有gallery-item類但不是空類,它會得到樣式。 – Harry
啊,對於那個錯字錯誤感到抱歉。沒有注意到:( – Harry