I am trying to build a custom drop-down having collapsible options. Each option inside the drop-down will have sub options which when selected will give me the value.
On an abstract, the drop-down should look like below:
Considering above idea, I have tried my approach through a fiddle.
function myFunction() {
var x = document.getElementById("myDIV");
if (x.style.display === "none") {
x.style.display = "block";
} else {
x.style.display = "none";
}
}
.main-div {
display: inline-block;
padding: 15px;
width: 180px;
cursor:pointer;
border: 1px solid salmon;
}
.inner-div {
position: absolute;
width: 210px;
top: 58px;
left: 8px;
height: 300px;
border: 1px solid salmon;
}
.inner-div > ul {
list-style-type: none;
border-bottom: 1px solid salmon;
margin: 5px;
padding: 10px;
}
.inner-div > ul > span {
display: inline;
}
.inner-div .acc-input {
position: absolute;
opacity: 0;
}
.inner-div .acc-input:checked ~ .acc-sub-cat {
display: block;
}
.inner-div .acc-sub-cat {
display: none;
overflow: hidden;
}
<div class="main-div" onclick="myFunction()"> Select Items
</div>
<div class="inner-div" id="myDIV">
<ul>
<li>
<input class="acc-input" type="checkbox" id="group-1">
<label for="group-1"><span>Group 1</span></label>
<ul class="acc-sub-cat">
<li><a><span>Item 1</span></a></li>
<li><a><span>Item 2</span></a></li>
</ul>
</li>
</ul>
</div>
But my snippet does not resemble the way I need it and I am not much experienced in CSS. Can anyone help me to arrive at the desired figure with smooth CSS, please?
PS: I am not using jquery
