<!--
Forum question answer only:
https://www.sitepoint.com/community/t/help-show-hide-div-with-css-issue/470847
-->
<button id="filter-toggle">SHOW FILTERS</button>
<div class="category_filter_box categoryfilter asp_sett_scroll">
<p>Filter options:</p>
<p>SOME COPY WILL BE HERE THAT IS TIED TO THE TOGGLE BUTTON</p>
</div>
/* Initially hide the div */
.category_filter_box.categoryfilter.asp_sett_scroll {
display: none;
border: 0px solid #ccc;
padding: 10px;
margin-top: 10px;
max-height: 200px;
overflow-y: auto;
}
/* Style the button (optional) */
button {
position: relative;
padding: 10px 30px 10px 20px;
background-color: #4caf50; /* Green */
border: none;
color: white;
text-align: center;
text-decoration: none;
display: inline-block;
min-width: 170px;
font-size: 16px;
cursor: pointer;
border-radius: 30px;
}
#filter-toggle:after {
content: "";
position: absolute;
right: 12px;
top: 10px;
width: 0;
height: 0;
border-top: 8px solid transparent;
border-bottom: 8px solid transparent;
border-left: 10px solid white;
transition: 0.8s ease;
}
#filter-toggle.open:after {
transform: rotate(90deg);
}
const toggleButton = document.getElementById("filter-toggle");
const filterDiv = document.querySelector(
".category_filter_box.categoryfilter.asp_sett_scroll"
);
//Hide div by default
filterDiv.style.display = "none";
toggleButton.addEventListener("click", () => {
if (filterDiv.style.display === "none") {
filterDiv.style.display = "block";
toggleButton.textContent = "HIDE FILTERS ";
toggleButton.classList.add("open");
} else {
filterDiv.style.display = "none";
toggleButton.textContent = "SHOW FILTERS";
toggleButton.classList.remove("open");
}
});
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.