I'm trying to create a mobile version toggle question and answer list. However, when I toggle the display block and none, the size of the container increases even though I added extra padding at the end. Is there a way to prevent this white space from occurring at the bottom of the container?
let question = document.querySelector(".question")
let answer = document.querySelector(".dropdown-content")
question.addEventListener("click", toggling)
function toggling(){
answer.classList.toggle("dropdown-display")
}
*{box-sizing: border-box}
body{
margin: 0;
padding: 0;
background-color: green;}
.container{
display: flex;
flex-direction: column;
align-items: center;}
.dropdowns{
border-radius: 1em;
max-width: 40rem;
background-color: white;
padding: 4em 2em 15em 2em;
margin-bottom: 5em;}
.dropdown-function{
width: 16.8rem;
padding: 0;
margin: 0;}
.question{
cursor: pointer;}
.dropdown-content{
display: none;}
.dropdown-display{
display: block;}
<div class = "container">
<main class = "dropdowns">
<div class = "dropdown-function">
<h2 class = "question"> Question 1</h2>
<p class = "dropdown-content"> Answer 1</p>
</div>
<div class = "dropdown-function">
<h2 class = "question"> Question 2</h2>
<p class = "dropdown-content"> Answer 2</p>
</div>
</main>
</div>