I have a collapsible list implemented using HTML and CSS. The list works properly, but I need a little modification.
Whenever I click an item in the list it expands. But as I click on another item in the same list, the previously expanded element gets collapsed while the clicked one gets expanded.
Please help me to apply the behavior that makes it possible to expand multiple list items at the same time.
I want it to be done in HTML and CSS only.
Here is the implementation I currently have. CSS styles:
.row { vertical-align: top; height: auto !important; } list { display: none; } .show { display: none; } .hide:target + .show { display: inline; } .hide:target { display: none; } .hide:target ~ .list { display:inline; } @media print { .hide, .show { display: none; } }
And the HTML markup:
<div class="row"> <a href="#hide1" class="hide" id="hide1">Expand</a> <a href="#show1" class="show" id="show1">Collapse</a> <div class="list"> <ul> <li>Item 1</li> <li>Item 2</li> <li>Item 3</li> </ul> </div> </div>
Close the head portion of the page, with the ending tag for the head of the page (</head>). Create the body of the HTML code. Type the tag for starting the body (<body>). Create the list content, including some HTML styling information for the users browser to use, for them to expand and collapse the list.
Just add data-toggle="collapse" and a data-target to element to automatically assign control of a collapsible element. The data-target attribute accepts a CSS selector to apply the collapse to. Be sure to add the class collapse to the collapsible element. If you'd like it to default open, add the additional class in.
<details> <summary>See More</summary> This text will be hidden if your browser supports it. </details>
One can find more information about <details>
HTML element, including other examples, on MDN.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With