我很難找到一種方法來做到這一點。這是我的結構:<div class="flex_container"> <div class="flex_item_9"> <div class="flex_label">First Label</div> <div class="flex_data">Some Data</div> </div> <div class="flex_item_9"> <div class="flex_label">Second Label</div> <div class="flex_data">Some Data</div> </div> <div class="flex_item_9"> <div class="flex_label">Third Label</div> <div class="flex_data">Some Data</div> </div></div>當從數據庫中提取該div結構時,它會在PHP While循環中重復進行。在桌面上,我想在第一個顯示后隱藏flex_label div。我只想為每個while循環顯示一次標簽。我認為:nth-child可以工作,所以我在CSS中嘗試了以下方法。div.flex_container .flex_label:nth-child(2) { display: none;}但是,沒有結果。瀏覽器中沒有任何更改。顯示所有的flex_labels。這是可以在CSS中處理的東西,還是我需要將一些東西合并到我的while循環中以向每個DIV塊添加其他類?
1 回答

至尊寶的傳說
TA貢獻1789條經驗 獲得超10個贊
以下選擇器應該起作用:
/* flex_label inside flex_container that is 2nd (or 3rd or 4th or ...) child */
.flex_container:nth-child(n + 2) .flex_label {}
/* flex_label inside flex_container that follows a flex_container */
.flex_container ~ .flex_container .flex_label {}
- 1 回答
- 0 關注
- 229 瀏覽
添加回答
舉報
0/150
提交
取消