私は項目のリストを持っており、それぞれにクラスがあり、クラスは全体で繰り返されています。各クラスの最初のインスタンスのみを表示したい。CSSだけでそれは可能ですか?
<ul>
<li class="red">red</li>
<li class="red">red</li>
<li class="blue">blue</li>
<li class="blue">blue</li>
<li class="yellow">yellow</li>
<li class="red">red</li>
<li class="yellow">yellow</li>
</ul>
ul li {display:none}
ul li .red:first-child, ul li .blue:first-child, ul li .yellow:first-child { display:block}
したがって、上記のコードでは、1 番目、3 番目、および 5 番目のリスト項目のみが表示されます。