I've found there's a simple way to count siblings of the <li>
tag and return a CSS style fit for the how many <li>
siblings there are:
ul{
list-style-type: none;
display: block;
}
#container{
width: 100%;
float: left;
height: 100%;
margin-left: 0;
margin-top: 0;
}
li:first-child:nth-last-child(1) {
height: 100%;
background-color: red;
width: 100%;
}
li:first-child:nth-last-child(2),
li:first-child:nth-last-child(2) ~ li {
height: 100%;
background-color: blue;
float: left;
width: 49%;
margin-left: 1%;
}
li:first-child:nth-last-child(3),
li:first-child:nth-last-child(3) ~ li {
height: 100%;
float: left;
background-color: red;
width: 33.333%;
}
li:first-child:nth-last-child(4),
li:first-child:nth-last-child(4) ~ li {
height: 100%;
background-color: blue;
float: left;
width: 24%;
margin-left: 1%;
}
<div id="container">
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
</ul>
</div>
I'm looking to hide <li>
tags with the class="hidden"
I've tried:
ul {
list-style: none;
}
li.hidden:first-child:nth-last-child(2),
li.hidden:first-child:nth-last-child(2) ~ li {
display: none;
}
li.hidden:first-child:nth-last-child(3),
li.hidden:first-child:nth-last-child(3) ~ li {
background-color: blue;
}
<ul>
<li class="hidden">1</li>
<li>2</li>
<li class="hidden">3</li>
<li>4</li>
</ul>
Is there a way to selectively detect and change the CSS style of a <li>
tag with the class of "hidden" based on the number of <li>
tags with the class "hidden" without affecting the <li>
tags without the class of "hidden"?