I have a HTML list that has rounded corners, the list items have distinct background colors and list items can be toggled via JavaScript:
$(function() {
$("#menu .header").on("click", function() {
$(this).nextUntil(".header").toggle();
});
});
body {
font: medium sans-serif;
}
#menu {
padding: 0;
list-style-type: none;
}
#menu li {
padding: 1em;
}
/**** colors ****/
#menu li {
color: #FFF;
background-color: #000;
}
#menu li.header {
color: #FFF;
background-color: #09F;
}
/**** corners ****/
#menu li:first-child {
border-radius: 1em 1em 0 0;
}
#menu li:last-child {
border-radius: 0 0 1em 1em;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<ul id="menu">
<li>Menu 1</li>
<li class="header">Menu 2 (click to toggle)</li>
<li>Menu 2-1</li>
<li>Menu 2-2</li>
<li>Menu 2-2</li>
<li class="header">Menu 3 (click to toggle)</li>
<li>Menu 3-1</li>
<li>Menu 3-2</li>
<li>Menu 3-3</li>
</ul>
Problem: the round corners at the bottom disappear when the last item (last-child) is hidden. I tried adding round corners to the parent (#menu) but it does not work since children have background colors.
I want the last visible child to have round corners. What is the best no-javascript solution to achieve the desired result?