For my projects, I typically utilize Bootstrap for styling and usually do not include any Javascript as it is unnecessary. However, I am now working on a project that requires a feature similar to Bootstrap's Accordion, which does require Javascript to function. Luckily, there is the standard <details>
HTML tag that can achieve the same functionality. The issue I am encountering is that I cannot easily apply Accordion styling to the <details>
tag.
This code snippet shows my current attempt where the accordion-header
class wraps around the entire body content:
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a7c5c8c8d3d4d3d5c6d7e79289978995">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet"/>
<div class="accordion">
<details class="accordion-item">
<summary class="">
<div class="accordion-header">
Title
</div>
</summary>
<div class="accordion-body">
<p>This is the body</p>
</div>
</details>
</div>
An alternative approach could be to style the summary
element to resemble an .alert
.