Show only if there are more than 2 children
2 answers
You can use a selector :only-child
and hide the li if it's the only one.
ul li:only-child{
display: none;
}
ul li:only-child {
display: none;
}
<ul>
<li>Don't Display</li>
</ul>
<ul>
<li>Display</li>
<li>Display</li>
</ul>
https://jsfiddle.net/90kx009u/
Here's the JS if you want to accomplish exactly what you ask:
let thelist = document.querySelector('.thelist')
if(thelist.childElementCount <= 1){
thelist.remove()
}
+7
source to share
You cannot directly "count" the total number of elements in CSS, so there is no way to apply the class only if there are 2 or more divs (you need JavaScript for this) See more here: How to add CSS if an element contains more than one child?
+1
source to share