考慮以下元素:樣式奇數和偶數同級元素 - 不包括那些設置爲顯示:無
<div class="accordion-content">
<div><?php the_field('f_1'); ?></div>
<div><?php the_field('f_2'); ?></div>
<div><?php the_field('f_3'); ?></div>
<div><?php the_field('f_4'); ?></div>
<div><?php the_field('f_5'); ?></div>
<div><?php the_field('f_6'); ?></div>
<div><?php the_field('f_7'); ?></div>
<div><?php the_field('f_8'); ?></div>
<div><?php the_field('f_9'); ?></div>
<div><?php the_field('f_10'); ?></div>
<div><?php the_field('f_11'); ?></div>
</div>
和造型
.accordion-content div:empty{display: none}
.accordion-content div:nth-of-type(odd) {
background-color:#f0f0f1;
}
.accordion-content div:nth-of-type(even){
background-color:#e1e1e4;
}
鏈接到靜態撥弄示例http://codepen.io/whispering_jack/pen/yMWoZj
如果用戶在顯示內容的字段中輸入數據,否則如果該字段爲空,則不顯示。
我想要實現的是條紋的交替顏色,但是當前的css也針對非顯示的元素,因此如果所有的字段沒有被填充顏色將不會交替。
任何人都可以提出一個解決方案,只針對顯示的div交替的背景顏色? CSS或SCSS選項歡迎,js最後的手段。
謝謝。
編輯:仍在追逐一些援助。
應用使用'顯示'div' id'交替的背景顏色CSS。 –
爲什麼不阻止使用PHP打印字段? – Charlie
@UkkarshDubey可以擴展嗎?使用display:none代碼中沒有內容的標籤仍然存在。 – JPB