I am currently designing a portfolio website using HTML, CSS, and vanilla JavaScript. I have implemented collapsing sections that expand when clicked on. However, the buttons for these sections are stacked vertically and I want to place them side by side. Being new to these languages with just a month of experience, I am unsure how to achieve this layout.
document.querySelectorAll(".collapse__button").forEach(button =>{
button.addEventListener("click", () =>{
const collapseContent = button.nextElementSibling;
button.classList.toggle("collapse__button--active");
if (button.classList.contains("collapse__button--active")){
collapseContent.style.maxHeight = collapseContent.scrollHeight + "px";
}else{
collapseContent.style.maxHeight = 0;
}
});
});
.collapse__button {
/* display: inline-block; */
padding: 1em 2em ;
background: var(--clr-dark);
color: var(--clr-light);
text-decoration: none;
cursor: pointer;
font-size: .8rem;
text-transform: uppercase;
letter-spacing: 2px;
font-weight: var(--fw-bold);
transition: transform 200ms ease-in-out;
max-width: 200px;
margin: 5em 5em;
border: 8px var(--clr-accent);
border-radius: 20px;
}
.collapse__button:hover{
transform: scale(1.1);
background: var(--clr-accent);
}
.collapse__button::after{
content: "\25be";
float: right;
transform: scale(1);
}
.collapse__content{
overflow: hidden;
max-height: 0;
transition: max-height 0.2s;
padding: 0 15px;
}
.collapse__button--active::after{
content: "\25b4";
}
.Title{
text-align: center;
}
<section class = "Title">
<p> Title of Example</p>
<div class = "collapse">
<button class = "collapse__button"> Example 1 </button>
<div class="collapse__content">
<p>
writing
</p>
</div>
</div>
<div class = "collapse">
<button class = "collapse__button"> Example 2 </button>
<div class="collapse__content">
<p>
more writing
</p>
</div>
</div>