I want to make li
element in alternate color but only those have a attribute data-filetype="image".
As soon as I add a new li
without adding data-filetype attribute
, my color sequence fails.
Link to JSBin is here
HTML Code:
<ul>
<li data-filetype="image">PNG Image</li><!-- It should be RED -->
<li data-filetype="image">PNG Image</li><!-- It should be ORANGE -->
<li>Normal Link</li><!-- After adding this li color sequence breaks -->
<li data-filetype="image">PNG Image</li><!-- It should be RED -->
<li data-filetype="image">PNG Image</li><!-- It should be ORANGE -->
</ul>
CSS:
ul li[data-filetype="image"]:nth-child(2n){color:orange}
ul li[data-filetype="image"]:nth-child(2n+1){color:red}