Create Expandable And Collapsible Sections Using CSS Grid – ExpandifyCSS

Category: Javascript | October 19, 2023
Author:armennersisyan
Views Total:107 views
Official Page:Go to website
Last Update:October 19, 2023
License:MIT

Preview:

Create Expandable And Collapsible Sections Using CSS Grid – ExpandifyCSS

Description:

ExpandifyCSS is an open-source project that helps create expandable and collapsible sections using CSS grid. JavaScript is only used to toggle the expanded state of the sections.

How to use it:

1. Download and import the ‘expandify.css’ stylesheet.

<link rel="stylesheet" href="expandify.css" />

2. Create a expandable and collapsible section.

<div class="expandableSection">
  <div class="expandableSection-inner">
    <div class="contentWrapper">
      ...
    </div>
  </div>
</div>

3. Create a button to toggle the section.

<button id="btn">Toggle</button>

4. Toggle the ‘expanded’ class on the element with the class ‘expandableSection’.

const toggleExpandableSection = () => {
  document.querySelector('.expandableSection').classList.toggle('expanded');
};

5. Attach the toggle function to the button with the ID ‘btn’.

document.getElementById('btn').addEventListener('click', toggleExpandableSection);

You Might Be Interested In:


Leave a Reply