How to have Accordin buttons' heights fill the remaining space evenly











up vote
1
down vote

favorite












I have developed a layout in which button elements should fill the empty space below them when they are closed . I tried several approaches but no luck.



Here is my code :






var accordion = document.getElementsByClassName("accordion");
var i;

for (i = 0; i < accordion.length; i++) {
accordion[i].addEventListener("click", function() {

panel = this.nextElementSibling;

if (panel.style.maxHeight){
panel.style.maxHeight = null;
} else {
for(j = 0; j < accordion.length; j++) {
if(j != i) {
accordion[j].nextElementSibling.style.maxHeight = null;
accordion[j].classList.remove('active');
}
}
panel.style.maxHeight = panel.scrollHeight + "px";
}

this.classList.toggle("active");
});
}

body {
margin: 0;
background-color: #e0d9d4;
}

.container {
height: 100%;
}

.about {
float: left;
width: 50%;
color : white;
background-color : black;
}

.projects {
float : right;
width : 50%;
}

.about h2 {
font-family: Clearface;
font-size : 80px;
padding: 30px;
}

.about p {
font-family: Clearface;
font-size : 30px;
padding: 30px;
}

.accordion {
background-color: #333648;
color: white;
cursor: pointer;
padding: 20px;
width: 100%;
border: none;
text-align: center;
outline: none;
font-size: 17px;
transition: 0.5s;

}

.active, .accordion:hover {
background-color: #ccc;
color: black;
}

.panel {
padding:0 18px;
background-color: white;
max-height: 0;
overflow-y: hidden;
transition: max-height 0.3s ease-out;
}

.img-responsive {
display: block;
max-width: 100%;
height: auto;
margin: 50px auto;
}

.header-img-responsive {
display: block;
width: 100%;
height: auto;
}

.post {
padding: 0 20%;
}

.title {
text-align: center;
color: #932D26;
}

<div class="container">
<div class="about">
<h2>
Hello!
</h2>
<p>
Lorem Ipsum är en utfyllnadstext från tryck- och förlagsindustrin. Lorem ipsum har varit standard ända sedan 1500-talet, när en okänd boksättare tog att antal bokstäver och blandade dem för att göra ett provexemplar av en bok. Lorem ipsum har inte bara överlevt fem århundraden, utan även övergången till elektronisk typografi utan större förändringar. Det blev allmänt känt på 1960-talet i samband med lanseringen av Letraset-ark med avsnitt av Lorem Ipsum, och senare med mjukvaror som Aldus PageMaker.
</p>
</div>

<div class="projects">
<button class="accordion">Project 1</button>
<div class="panel">
<div class="post">
<h2>TITLE HEADING</h2>
<p>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</p>
<div>
<img src="images/placeholder.jpg" class="img-responsive">
<img src="images/placeholder.jpg" class="img-responsive">
<img src="images/placeholder.jpg" class="img-responsive">
</div>
</div>
</div>

<button class="accordion">Project 2</button>
<div class="panel">
<div class="post">
<h2>TITLE HEADING</h2>
<p>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.


</p>
<div>
<img src="images/placeholder.jpg" class="img-responsive">
<img src="images/placeholder.jpg" class="img-responsive">
<img src="images/placeholder.jpg" class="img-responsive">
</div>
</div>
</div>

<button class="accordion">Project 3</button>
<div class="panel">
<div class="post">
<h2>TITLE HEADING</h2>
<p>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.


</p>
<div>
<img src="images/placeholder.jpg" class="img-responsive">
<img src="images/placeholder.jpg" class="img-responsive">
<img src="images/placeholder.jpg" class="img-responsive">
</div>
</div>
</div>

<button class="accordion">Project 4</button>
<div class="panel">
<div class="post">
<h2>TITLE HEADING</h2>
<p>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.


</p>
<div>
<img src="images/placeholder.jpg" class="img-responsive">
<img src="images/placeholder.jpg" class="img-responsive">
<img src="images/placeholder.jpg" class="img-responsive">
</div>
</div>
</div>

<button class="accordion">Project 5</button>
<div class="panel">
<div class="post">
<h2>TITLE HEADING</h2>
<p>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.


</p>
<div>
<img src="images/placeholder.jpg" class="img-responsive">
<img src="images/placeholder.jpg" class="img-responsive">
<img src="images/placeholder.jpg" class="img-responsive">
</div>
</div>
</div>
</div>
</div>





how can I achieve this effect ?










share|improve this question


























    up vote
    1
    down vote

    favorite












    I have developed a layout in which button elements should fill the empty space below them when they are closed . I tried several approaches but no luck.



    Here is my code :






    var accordion = document.getElementsByClassName("accordion");
    var i;

    for (i = 0; i < accordion.length; i++) {
    accordion[i].addEventListener("click", function() {

    panel = this.nextElementSibling;

    if (panel.style.maxHeight){
    panel.style.maxHeight = null;
    } else {
    for(j = 0; j < accordion.length; j++) {
    if(j != i) {
    accordion[j].nextElementSibling.style.maxHeight = null;
    accordion[j].classList.remove('active');
    }
    }
    panel.style.maxHeight = panel.scrollHeight + "px";
    }

    this.classList.toggle("active");
    });
    }

    body {
    margin: 0;
    background-color: #e0d9d4;
    }

    .container {
    height: 100%;
    }

    .about {
    float: left;
    width: 50%;
    color : white;
    background-color : black;
    }

    .projects {
    float : right;
    width : 50%;
    }

    .about h2 {
    font-family: Clearface;
    font-size : 80px;
    padding: 30px;
    }

    .about p {
    font-family: Clearface;
    font-size : 30px;
    padding: 30px;
    }

    .accordion {
    background-color: #333648;
    color: white;
    cursor: pointer;
    padding: 20px;
    width: 100%;
    border: none;
    text-align: center;
    outline: none;
    font-size: 17px;
    transition: 0.5s;

    }

    .active, .accordion:hover {
    background-color: #ccc;
    color: black;
    }

    .panel {
    padding:0 18px;
    background-color: white;
    max-height: 0;
    overflow-y: hidden;
    transition: max-height 0.3s ease-out;
    }

    .img-responsive {
    display: block;
    max-width: 100%;
    height: auto;
    margin: 50px auto;
    }

    .header-img-responsive {
    display: block;
    width: 100%;
    height: auto;
    }

    .post {
    padding: 0 20%;
    }

    .title {
    text-align: center;
    color: #932D26;
    }

    <div class="container">
    <div class="about">
    <h2>
    Hello!
    </h2>
    <p>
    Lorem Ipsum är en utfyllnadstext från tryck- och förlagsindustrin. Lorem ipsum har varit standard ända sedan 1500-talet, när en okänd boksättare tog att antal bokstäver och blandade dem för att göra ett provexemplar av en bok. Lorem ipsum har inte bara överlevt fem århundraden, utan även övergången till elektronisk typografi utan större förändringar. Det blev allmänt känt på 1960-talet i samband med lanseringen av Letraset-ark med avsnitt av Lorem Ipsum, och senare med mjukvaror som Aldus PageMaker.
    </p>
    </div>

    <div class="projects">
    <button class="accordion">Project 1</button>
    <div class="panel">
    <div class="post">
    <h2>TITLE HEADING</h2>
    <p>
    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
    </p>
    <div>
    <img src="images/placeholder.jpg" class="img-responsive">
    <img src="images/placeholder.jpg" class="img-responsive">
    <img src="images/placeholder.jpg" class="img-responsive">
    </div>
    </div>
    </div>

    <button class="accordion">Project 2</button>
    <div class="panel">
    <div class="post">
    <h2>TITLE HEADING</h2>
    <p>
    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.


    </p>
    <div>
    <img src="images/placeholder.jpg" class="img-responsive">
    <img src="images/placeholder.jpg" class="img-responsive">
    <img src="images/placeholder.jpg" class="img-responsive">
    </div>
    </div>
    </div>

    <button class="accordion">Project 3</button>
    <div class="panel">
    <div class="post">
    <h2>TITLE HEADING</h2>
    <p>
    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.


    </p>
    <div>
    <img src="images/placeholder.jpg" class="img-responsive">
    <img src="images/placeholder.jpg" class="img-responsive">
    <img src="images/placeholder.jpg" class="img-responsive">
    </div>
    </div>
    </div>

    <button class="accordion">Project 4</button>
    <div class="panel">
    <div class="post">
    <h2>TITLE HEADING</h2>
    <p>
    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.


    </p>
    <div>
    <img src="images/placeholder.jpg" class="img-responsive">
    <img src="images/placeholder.jpg" class="img-responsive">
    <img src="images/placeholder.jpg" class="img-responsive">
    </div>
    </div>
    </div>

    <button class="accordion">Project 5</button>
    <div class="panel">
    <div class="post">
    <h2>TITLE HEADING</h2>
    <p>
    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.


    </p>
    <div>
    <img src="images/placeholder.jpg" class="img-responsive">
    <img src="images/placeholder.jpg" class="img-responsive">
    <img src="images/placeholder.jpg" class="img-responsive">
    </div>
    </div>
    </div>
    </div>
    </div>





    how can I achieve this effect ?










    share|improve this question
























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I have developed a layout in which button elements should fill the empty space below them when they are closed . I tried several approaches but no luck.



      Here is my code :






      var accordion = document.getElementsByClassName("accordion");
      var i;

      for (i = 0; i < accordion.length; i++) {
      accordion[i].addEventListener("click", function() {

      panel = this.nextElementSibling;

      if (panel.style.maxHeight){
      panel.style.maxHeight = null;
      } else {
      for(j = 0; j < accordion.length; j++) {
      if(j != i) {
      accordion[j].nextElementSibling.style.maxHeight = null;
      accordion[j].classList.remove('active');
      }
      }
      panel.style.maxHeight = panel.scrollHeight + "px";
      }

      this.classList.toggle("active");
      });
      }

      body {
      margin: 0;
      background-color: #e0d9d4;
      }

      .container {
      height: 100%;
      }

      .about {
      float: left;
      width: 50%;
      color : white;
      background-color : black;
      }

      .projects {
      float : right;
      width : 50%;
      }

      .about h2 {
      font-family: Clearface;
      font-size : 80px;
      padding: 30px;
      }

      .about p {
      font-family: Clearface;
      font-size : 30px;
      padding: 30px;
      }

      .accordion {
      background-color: #333648;
      color: white;
      cursor: pointer;
      padding: 20px;
      width: 100%;
      border: none;
      text-align: center;
      outline: none;
      font-size: 17px;
      transition: 0.5s;

      }

      .active, .accordion:hover {
      background-color: #ccc;
      color: black;
      }

      .panel {
      padding:0 18px;
      background-color: white;
      max-height: 0;
      overflow-y: hidden;
      transition: max-height 0.3s ease-out;
      }

      .img-responsive {
      display: block;
      max-width: 100%;
      height: auto;
      margin: 50px auto;
      }

      .header-img-responsive {
      display: block;
      width: 100%;
      height: auto;
      }

      .post {
      padding: 0 20%;
      }

      .title {
      text-align: center;
      color: #932D26;
      }

      <div class="container">
      <div class="about">
      <h2>
      Hello!
      </h2>
      <p>
      Lorem Ipsum är en utfyllnadstext från tryck- och förlagsindustrin. Lorem ipsum har varit standard ända sedan 1500-talet, när en okänd boksättare tog att antal bokstäver och blandade dem för att göra ett provexemplar av en bok. Lorem ipsum har inte bara överlevt fem århundraden, utan även övergången till elektronisk typografi utan större förändringar. Det blev allmänt känt på 1960-talet i samband med lanseringen av Letraset-ark med avsnitt av Lorem Ipsum, och senare med mjukvaror som Aldus PageMaker.
      </p>
      </div>

      <div class="projects">
      <button class="accordion">Project 1</button>
      <div class="panel">
      <div class="post">
      <h2>TITLE HEADING</h2>
      <p>
      Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
      </p>
      <div>
      <img src="images/placeholder.jpg" class="img-responsive">
      <img src="images/placeholder.jpg" class="img-responsive">
      <img src="images/placeholder.jpg" class="img-responsive">
      </div>
      </div>
      </div>

      <button class="accordion">Project 2</button>
      <div class="panel">
      <div class="post">
      <h2>TITLE HEADING</h2>
      <p>
      Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.


      </p>
      <div>
      <img src="images/placeholder.jpg" class="img-responsive">
      <img src="images/placeholder.jpg" class="img-responsive">
      <img src="images/placeholder.jpg" class="img-responsive">
      </div>
      </div>
      </div>

      <button class="accordion">Project 3</button>
      <div class="panel">
      <div class="post">
      <h2>TITLE HEADING</h2>
      <p>
      Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.


      </p>
      <div>
      <img src="images/placeholder.jpg" class="img-responsive">
      <img src="images/placeholder.jpg" class="img-responsive">
      <img src="images/placeholder.jpg" class="img-responsive">
      </div>
      </div>
      </div>

      <button class="accordion">Project 4</button>
      <div class="panel">
      <div class="post">
      <h2>TITLE HEADING</h2>
      <p>
      Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.


      </p>
      <div>
      <img src="images/placeholder.jpg" class="img-responsive">
      <img src="images/placeholder.jpg" class="img-responsive">
      <img src="images/placeholder.jpg" class="img-responsive">
      </div>
      </div>
      </div>

      <button class="accordion">Project 5</button>
      <div class="panel">
      <div class="post">
      <h2>TITLE HEADING</h2>
      <p>
      Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.


      </p>
      <div>
      <img src="images/placeholder.jpg" class="img-responsive">
      <img src="images/placeholder.jpg" class="img-responsive">
      <img src="images/placeholder.jpg" class="img-responsive">
      </div>
      </div>
      </div>
      </div>
      </div>





      how can I achieve this effect ?










      share|improve this question













      I have developed a layout in which button elements should fill the empty space below them when they are closed . I tried several approaches but no luck.



      Here is my code :






      var accordion = document.getElementsByClassName("accordion");
      var i;

      for (i = 0; i < accordion.length; i++) {
      accordion[i].addEventListener("click", function() {

      panel = this.nextElementSibling;

      if (panel.style.maxHeight){
      panel.style.maxHeight = null;
      } else {
      for(j = 0; j < accordion.length; j++) {
      if(j != i) {
      accordion[j].nextElementSibling.style.maxHeight = null;
      accordion[j].classList.remove('active');
      }
      }
      panel.style.maxHeight = panel.scrollHeight + "px";
      }

      this.classList.toggle("active");
      });
      }

      body {
      margin: 0;
      background-color: #e0d9d4;
      }

      .container {
      height: 100%;
      }

      .about {
      float: left;
      width: 50%;
      color : white;
      background-color : black;
      }

      .projects {
      float : right;
      width : 50%;
      }

      .about h2 {
      font-family: Clearface;
      font-size : 80px;
      padding: 30px;
      }

      .about p {
      font-family: Clearface;
      font-size : 30px;
      padding: 30px;
      }

      .accordion {
      background-color: #333648;
      color: white;
      cursor: pointer;
      padding: 20px;
      width: 100%;
      border: none;
      text-align: center;
      outline: none;
      font-size: 17px;
      transition: 0.5s;

      }

      .active, .accordion:hover {
      background-color: #ccc;
      color: black;
      }

      .panel {
      padding:0 18px;
      background-color: white;
      max-height: 0;
      overflow-y: hidden;
      transition: max-height 0.3s ease-out;
      }

      .img-responsive {
      display: block;
      max-width: 100%;
      height: auto;
      margin: 50px auto;
      }

      .header-img-responsive {
      display: block;
      width: 100%;
      height: auto;
      }

      .post {
      padding: 0 20%;
      }

      .title {
      text-align: center;
      color: #932D26;
      }

      <div class="container">
      <div class="about">
      <h2>
      Hello!
      </h2>
      <p>
      Lorem Ipsum är en utfyllnadstext från tryck- och förlagsindustrin. Lorem ipsum har varit standard ända sedan 1500-talet, när en okänd boksättare tog att antal bokstäver och blandade dem för att göra ett provexemplar av en bok. Lorem ipsum har inte bara överlevt fem århundraden, utan även övergången till elektronisk typografi utan större förändringar. Det blev allmänt känt på 1960-talet i samband med lanseringen av Letraset-ark med avsnitt av Lorem Ipsum, och senare med mjukvaror som Aldus PageMaker.
      </p>
      </div>

      <div class="projects">
      <button class="accordion">Project 1</button>
      <div class="panel">
      <div class="post">
      <h2>TITLE HEADING</h2>
      <p>
      Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
      </p>
      <div>
      <img src="images/placeholder.jpg" class="img-responsive">
      <img src="images/placeholder.jpg" class="img-responsive">
      <img src="images/placeholder.jpg" class="img-responsive">
      </div>
      </div>
      </div>

      <button class="accordion">Project 2</button>
      <div class="panel">
      <div class="post">
      <h2>TITLE HEADING</h2>
      <p>
      Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.


      </p>
      <div>
      <img src="images/placeholder.jpg" class="img-responsive">
      <img src="images/placeholder.jpg" class="img-responsive">
      <img src="images/placeholder.jpg" class="img-responsive">
      </div>
      </div>
      </div>

      <button class="accordion">Project 3</button>
      <div class="panel">
      <div class="post">
      <h2>TITLE HEADING</h2>
      <p>
      Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.


      </p>
      <div>
      <img src="images/placeholder.jpg" class="img-responsive">
      <img src="images/placeholder.jpg" class="img-responsive">
      <img src="images/placeholder.jpg" class="img-responsive">
      </div>
      </div>
      </div>

      <button class="accordion">Project 4</button>
      <div class="panel">
      <div class="post">
      <h2>TITLE HEADING</h2>
      <p>
      Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.


      </p>
      <div>
      <img src="images/placeholder.jpg" class="img-responsive">
      <img src="images/placeholder.jpg" class="img-responsive">
      <img src="images/placeholder.jpg" class="img-responsive">
      </div>
      </div>
      </div>

      <button class="accordion">Project 5</button>
      <div class="panel">
      <div class="post">
      <h2>TITLE HEADING</h2>
      <p>
      Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.


      </p>
      <div>
      <img src="images/placeholder.jpg" class="img-responsive">
      <img src="images/placeholder.jpg" class="img-responsive">
      <img src="images/placeholder.jpg" class="img-responsive">
      </div>
      </div>
      </div>
      </div>
      </div>





      how can I achieve this effect ?






      var accordion = document.getElementsByClassName("accordion");
      var i;

      for (i = 0; i < accordion.length; i++) {
      accordion[i].addEventListener("click", function() {

      panel = this.nextElementSibling;

      if (panel.style.maxHeight){
      panel.style.maxHeight = null;
      } else {
      for(j = 0; j < accordion.length; j++) {
      if(j != i) {
      accordion[j].nextElementSibling.style.maxHeight = null;
      accordion[j].classList.remove('active');
      }
      }
      panel.style.maxHeight = panel.scrollHeight + "px";
      }

      this.classList.toggle("active");
      });
      }

      body {
      margin: 0;
      background-color: #e0d9d4;
      }

      .container {
      height: 100%;
      }

      .about {
      float: left;
      width: 50%;
      color : white;
      background-color : black;
      }

      .projects {
      float : right;
      width : 50%;
      }

      .about h2 {
      font-family: Clearface;
      font-size : 80px;
      padding: 30px;
      }

      .about p {
      font-family: Clearface;
      font-size : 30px;
      padding: 30px;
      }

      .accordion {
      background-color: #333648;
      color: white;
      cursor: pointer;
      padding: 20px;
      width: 100%;
      border: none;
      text-align: center;
      outline: none;
      font-size: 17px;
      transition: 0.5s;

      }

      .active, .accordion:hover {
      background-color: #ccc;
      color: black;
      }

      .panel {
      padding:0 18px;
      background-color: white;
      max-height: 0;
      overflow-y: hidden;
      transition: max-height 0.3s ease-out;
      }

      .img-responsive {
      display: block;
      max-width: 100%;
      height: auto;
      margin: 50px auto;
      }

      .header-img-responsive {
      display: block;
      width: 100%;
      height: auto;
      }

      .post {
      padding: 0 20%;
      }

      .title {
      text-align: center;
      color: #932D26;
      }

      <div class="container">
      <div class="about">
      <h2>
      Hello!
      </h2>
      <p>
      Lorem Ipsum är en utfyllnadstext från tryck- och förlagsindustrin. Lorem ipsum har varit standard ända sedan 1500-talet, när en okänd boksättare tog att antal bokstäver och blandade dem för att göra ett provexemplar av en bok. Lorem ipsum har inte bara överlevt fem århundraden, utan även övergången till elektronisk typografi utan större förändringar. Det blev allmänt känt på 1960-talet i samband med lanseringen av Letraset-ark med avsnitt av Lorem Ipsum, och senare med mjukvaror som Aldus PageMaker.
      </p>
      </div>

      <div class="projects">
      <button class="accordion">Project 1</button>
      <div class="panel">
      <div class="post">
      <h2>TITLE HEADING</h2>
      <p>
      Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
      </p>
      <div>
      <img src="images/placeholder.jpg" class="img-responsive">
      <img src="images/placeholder.jpg" class="img-responsive">
      <img src="images/placeholder.jpg" class="img-responsive">
      </div>
      </div>
      </div>

      <button class="accordion">Project 2</button>
      <div class="panel">
      <div class="post">
      <h2>TITLE HEADING</h2>
      <p>
      Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.


      </p>
      <div>
      <img src="images/placeholder.jpg" class="img-responsive">
      <img src="images/placeholder.jpg" class="img-responsive">
      <img src="images/placeholder.jpg" class="img-responsive">
      </div>
      </div>
      </div>

      <button class="accordion">Project 3</button>
      <div class="panel">
      <div class="post">
      <h2>TITLE HEADING</h2>
      <p>
      Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.


      </p>
      <div>
      <img src="images/placeholder.jpg" class="img-responsive">
      <img src="images/placeholder.jpg" class="img-responsive">
      <img src="images/placeholder.jpg" class="img-responsive">
      </div>
      </div>
      </div>

      <button class="accordion">Project 4</button>
      <div class="panel">
      <div class="post">
      <h2>TITLE HEADING</h2>
      <p>
      Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.


      </p>
      <div>
      <img src="images/placeholder.jpg" class="img-responsive">
      <img src="images/placeholder.jpg" class="img-responsive">
      <img src="images/placeholder.jpg" class="img-responsive">
      </div>
      </div>
      </div>

      <button class="accordion">Project 5</button>
      <div class="panel">
      <div class="post">
      <h2>TITLE HEADING</h2>
      <p>
      Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.


      </p>
      <div>
      <img src="images/placeholder.jpg" class="img-responsive">
      <img src="images/placeholder.jpg" class="img-responsive">
      <img src="images/placeholder.jpg" class="img-responsive">
      </div>
      </div>
      </div>
      </div>
      </div>





      var accordion = document.getElementsByClassName("accordion");
      var i;

      for (i = 0; i < accordion.length; i++) {
      accordion[i].addEventListener("click", function() {

      panel = this.nextElementSibling;

      if (panel.style.maxHeight){
      panel.style.maxHeight = null;
      } else {
      for(j = 0; j < accordion.length; j++) {
      if(j != i) {
      accordion[j].nextElementSibling.style.maxHeight = null;
      accordion[j].classList.remove('active');
      }
      }
      panel.style.maxHeight = panel.scrollHeight + "px";
      }

      this.classList.toggle("active");
      });
      }

      body {
      margin: 0;
      background-color: #e0d9d4;
      }

      .container {
      height: 100%;
      }

      .about {
      float: left;
      width: 50%;
      color : white;
      background-color : black;
      }

      .projects {
      float : right;
      width : 50%;
      }

      .about h2 {
      font-family: Clearface;
      font-size : 80px;
      padding: 30px;
      }

      .about p {
      font-family: Clearface;
      font-size : 30px;
      padding: 30px;
      }

      .accordion {
      background-color: #333648;
      color: white;
      cursor: pointer;
      padding: 20px;
      width: 100%;
      border: none;
      text-align: center;
      outline: none;
      font-size: 17px;
      transition: 0.5s;

      }

      .active, .accordion:hover {
      background-color: #ccc;
      color: black;
      }

      .panel {
      padding:0 18px;
      background-color: white;
      max-height: 0;
      overflow-y: hidden;
      transition: max-height 0.3s ease-out;
      }

      .img-responsive {
      display: block;
      max-width: 100%;
      height: auto;
      margin: 50px auto;
      }

      .header-img-responsive {
      display: block;
      width: 100%;
      height: auto;
      }

      .post {
      padding: 0 20%;
      }

      .title {
      text-align: center;
      color: #932D26;
      }

      <div class="container">
      <div class="about">
      <h2>
      Hello!
      </h2>
      <p>
      Lorem Ipsum är en utfyllnadstext från tryck- och förlagsindustrin. Lorem ipsum har varit standard ända sedan 1500-talet, när en okänd boksättare tog att antal bokstäver och blandade dem för att göra ett provexemplar av en bok. Lorem ipsum har inte bara överlevt fem århundraden, utan även övergången till elektronisk typografi utan större förändringar. Det blev allmänt känt på 1960-talet i samband med lanseringen av Letraset-ark med avsnitt av Lorem Ipsum, och senare med mjukvaror som Aldus PageMaker.
      </p>
      </div>

      <div class="projects">
      <button class="accordion">Project 1</button>
      <div class="panel">
      <div class="post">
      <h2>TITLE HEADING</h2>
      <p>
      Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
      </p>
      <div>
      <img src="images/placeholder.jpg" class="img-responsive">
      <img src="images/placeholder.jpg" class="img-responsive">
      <img src="images/placeholder.jpg" class="img-responsive">
      </div>
      </div>
      </div>

      <button class="accordion">Project 2</button>
      <div class="panel">
      <div class="post">
      <h2>TITLE HEADING</h2>
      <p>
      Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.


      </p>
      <div>
      <img src="images/placeholder.jpg" class="img-responsive">
      <img src="images/placeholder.jpg" class="img-responsive">
      <img src="images/placeholder.jpg" class="img-responsive">
      </div>
      </div>
      </div>

      <button class="accordion">Project 3</button>
      <div class="panel">
      <div class="post">
      <h2>TITLE HEADING</h2>
      <p>
      Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.


      </p>
      <div>
      <img src="images/placeholder.jpg" class="img-responsive">
      <img src="images/placeholder.jpg" class="img-responsive">
      <img src="images/placeholder.jpg" class="img-responsive">
      </div>
      </div>
      </div>

      <button class="accordion">Project 4</button>
      <div class="panel">
      <div class="post">
      <h2>TITLE HEADING</h2>
      <p>
      Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.


      </p>
      <div>
      <img src="images/placeholder.jpg" class="img-responsive">
      <img src="images/placeholder.jpg" class="img-responsive">
      <img src="images/placeholder.jpg" class="img-responsive">
      </div>
      </div>
      </div>

      <button class="accordion">Project 5</button>
      <div class="panel">
      <div class="post">
      <h2>TITLE HEADING</h2>
      <p>
      Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.


      </p>
      <div>
      <img src="images/placeholder.jpg" class="img-responsive">
      <img src="images/placeholder.jpg" class="img-responsive">
      <img src="images/placeholder.jpg" class="img-responsive">
      </div>
      </div>
      </div>
      </div>
      </div>






      javascript html css css3 layout






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 7 at 20:52









      Ramin

      1,76242246




      1,76242246
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote













          Add display: flex in .container class and add height: 20% in class accordion and it'll work. Check following working code.






          var accordion = document.getElementsByClassName("accordion");
          var i;

          for (i = 0; i < accordion.length; i++) {
          accordion[i].addEventListener("click", function() {

          panel = this.nextElementSibling;

          if (panel.style.maxHeight){
          panel.style.maxHeight = null;
          } else {
          for(j = 0; j < accordion.length; j++) {
          if(j != i) {
          accordion[j].nextElementSibling.style.maxHeight = null;
          accordion[j].classList.remove('active');
          }
          }
          panel.style.maxHeight = panel.scrollHeight + "px";
          }

          this.classList.toggle("active");
          });
          }

          body {
          margin: 0;
          background-color: #e0d9d4;
          }

          .container {
          height: 100%;
          display: flex;
          }

          .about {
          float: left;
          width: 50%;
          color : white;
          background-color : black;
          }

          .projects {
          float : right;
          width : 50%;
          }

          .about h2 {
          font-family: Clearface;
          font-size : 80px;
          padding: 30px;
          }

          .about p {
          font-family: Clearface;
          font-size : 30px;
          padding: 30px;
          }

          .accordion {
          background-color: #333648;
          color: white;
          cursor: pointer;
          padding: 20px;
          width: 100%;
          height: 20%;
          border: none;
          text-align: center;
          outline: none;
          font-size: 17px;
          transition: 0.5s;

          }

          .active, .accordion:hover {
          background-color: #ccc;
          color: black;
          }

          .panel {
          padding:0 18px;
          background-color: white;
          max-height: 0;
          overflow-y: hidden;
          transition: max-height 0.3s ease-out;
          }

          .img-responsive {
          display: block;
          max-width: 100%;
          height: auto;
          margin: 50px auto;
          }

          .header-img-responsive {
          display: block;
          width: 100%;
          height: auto;
          }

          .post {
          padding: 0 20%;
          }

          .title {
          text-align: center;
          color: #932D26;
          }

          <div class="container">
          <div class="about">
          <h2>
          Hello!
          </h2>
          <p>
          Lorem Ipsum är en utfyllnadstext från tryck- och förlagsindustrin. Lorem ipsum har varit standard ända sedan 1500-talet, när en okänd boksättare tog att antal bokstäver och blandade dem för att göra ett provexemplar av en bok. Lorem ipsum har inte bara överlevt fem århundraden, utan även övergången till elektronisk typografi utan större förändringar. Det blev allmänt känt på 1960-talet i samband med lanseringen av Letraset-ark med avsnitt av Lorem Ipsum, och senare med mjukvaror som Aldus PageMaker.
          </p>
          </div>

          <div class="projects">
          <button class="accordion">Project 1</button>
          <div class="panel">
          <div class="post">
          <h2>TITLE HEADING</h2>
          <p>
          Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
          </p>
          <div>
          <img src="images/placeholder.jpg" class="img-responsive">
          <img src="images/placeholder.jpg" class="img-responsive">
          <img src="images/placeholder.jpg" class="img-responsive">
          </div>
          </div>
          </div>

          <button class="accordion">Project 2</button>
          <div class="panel">
          <div class="post">
          <h2>TITLE HEADING</h2>
          <p>
          Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.


          </p>
          <div>
          <img src="images/placeholder.jpg" class="img-responsive">
          <img src="images/placeholder.jpg" class="img-responsive">
          <img src="images/placeholder.jpg" class="img-responsive">
          </div>
          </div>
          </div>

          <button class="accordion">Project 3</button>
          <div class="panel">
          <div class="post">
          <h2>TITLE HEADING</h2>
          <p>
          Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.


          </p>
          <div>
          <img src="images/placeholder.jpg" class="img-responsive">
          <img src="images/placeholder.jpg" class="img-responsive">
          <img src="images/placeholder.jpg" class="img-responsive">
          </div>
          </div>
          </div>

          <button class="accordion">Project 4</button>
          <div class="panel">
          <div class="post">
          <h2>TITLE HEADING</h2>
          <p>
          Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.


          </p>
          <div>
          <img src="images/placeholder.jpg" class="img-responsive">
          <img src="images/placeholder.jpg" class="img-responsive">
          <img src="images/placeholder.jpg" class="img-responsive">
          </div>
          </div>
          </div>

          <button class="accordion">Project 5</button>
          <div class="panel">
          <div class="post">
          <h2>TITLE HEADING</h2>
          <p>
          Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.


          </p>
          <div>
          <img src="images/placeholder.jpg" class="img-responsive">
          <img src="images/placeholder.jpg" class="img-responsive">
          <img src="images/placeholder.jpg" class="img-responsive">
          </div>
          </div>
          </div>
          </div>
          </div>








          share|improve this answer





















          • What to do if I wanted them to keep their height fixed whether they are open or not ?
            – Ramin
            Nov 7 at 21:26











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53197637%2fhow-to-have-accordin-buttons-heights-fill-the-remaining-space-evenly%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote













          Add display: flex in .container class and add height: 20% in class accordion and it'll work. Check following working code.






          var accordion = document.getElementsByClassName("accordion");
          var i;

          for (i = 0; i < accordion.length; i++) {
          accordion[i].addEventListener("click", function() {

          panel = this.nextElementSibling;

          if (panel.style.maxHeight){
          panel.style.maxHeight = null;
          } else {
          for(j = 0; j < accordion.length; j++) {
          if(j != i) {
          accordion[j].nextElementSibling.style.maxHeight = null;
          accordion[j].classList.remove('active');
          }
          }
          panel.style.maxHeight = panel.scrollHeight + "px";
          }

          this.classList.toggle("active");
          });
          }

          body {
          margin: 0;
          background-color: #e0d9d4;
          }

          .container {
          height: 100%;
          display: flex;
          }

          .about {
          float: left;
          width: 50%;
          color : white;
          background-color : black;
          }

          .projects {
          float : right;
          width : 50%;
          }

          .about h2 {
          font-family: Clearface;
          font-size : 80px;
          padding: 30px;
          }

          .about p {
          font-family: Clearface;
          font-size : 30px;
          padding: 30px;
          }

          .accordion {
          background-color: #333648;
          color: white;
          cursor: pointer;
          padding: 20px;
          width: 100%;
          height: 20%;
          border: none;
          text-align: center;
          outline: none;
          font-size: 17px;
          transition: 0.5s;

          }

          .active, .accordion:hover {
          background-color: #ccc;
          color: black;
          }

          .panel {
          padding:0 18px;
          background-color: white;
          max-height: 0;
          overflow-y: hidden;
          transition: max-height 0.3s ease-out;
          }

          .img-responsive {
          display: block;
          max-width: 100%;
          height: auto;
          margin: 50px auto;
          }

          .header-img-responsive {
          display: block;
          width: 100%;
          height: auto;
          }

          .post {
          padding: 0 20%;
          }

          .title {
          text-align: center;
          color: #932D26;
          }

          <div class="container">
          <div class="about">
          <h2>
          Hello!
          </h2>
          <p>
          Lorem Ipsum är en utfyllnadstext från tryck- och förlagsindustrin. Lorem ipsum har varit standard ända sedan 1500-talet, när en okänd boksättare tog att antal bokstäver och blandade dem för att göra ett provexemplar av en bok. Lorem ipsum har inte bara överlevt fem århundraden, utan även övergången till elektronisk typografi utan större förändringar. Det blev allmänt känt på 1960-talet i samband med lanseringen av Letraset-ark med avsnitt av Lorem Ipsum, och senare med mjukvaror som Aldus PageMaker.
          </p>
          </div>

          <div class="projects">
          <button class="accordion">Project 1</button>
          <div class="panel">
          <div class="post">
          <h2>TITLE HEADING</h2>
          <p>
          Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
          </p>
          <div>
          <img src="images/placeholder.jpg" class="img-responsive">
          <img src="images/placeholder.jpg" class="img-responsive">
          <img src="images/placeholder.jpg" class="img-responsive">
          </div>
          </div>
          </div>

          <button class="accordion">Project 2</button>
          <div class="panel">
          <div class="post">
          <h2>TITLE HEADING</h2>
          <p>
          Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.


          </p>
          <div>
          <img src="images/placeholder.jpg" class="img-responsive">
          <img src="images/placeholder.jpg" class="img-responsive">
          <img src="images/placeholder.jpg" class="img-responsive">
          </div>
          </div>
          </div>

          <button class="accordion">Project 3</button>
          <div class="panel">
          <div class="post">
          <h2>TITLE HEADING</h2>
          <p>
          Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.


          </p>
          <div>
          <img src="images/placeholder.jpg" class="img-responsive">
          <img src="images/placeholder.jpg" class="img-responsive">
          <img src="images/placeholder.jpg" class="img-responsive">
          </div>
          </div>
          </div>

          <button class="accordion">Project 4</button>
          <div class="panel">
          <div class="post">
          <h2>TITLE HEADING</h2>
          <p>
          Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.


          </p>
          <div>
          <img src="images/placeholder.jpg" class="img-responsive">
          <img src="images/placeholder.jpg" class="img-responsive">
          <img src="images/placeholder.jpg" class="img-responsive">
          </div>
          </div>
          </div>

          <button class="accordion">Project 5</button>
          <div class="panel">
          <div class="post">
          <h2>TITLE HEADING</h2>
          <p>
          Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.


          </p>
          <div>
          <img src="images/placeholder.jpg" class="img-responsive">
          <img src="images/placeholder.jpg" class="img-responsive">
          <img src="images/placeholder.jpg" class="img-responsive">
          </div>
          </div>
          </div>
          </div>
          </div>








          share|improve this answer





















          • What to do if I wanted them to keep their height fixed whether they are open or not ?
            – Ramin
            Nov 7 at 21:26















          up vote
          1
          down vote













          Add display: flex in .container class and add height: 20% in class accordion and it'll work. Check following working code.






          var accordion = document.getElementsByClassName("accordion");
          var i;

          for (i = 0; i < accordion.length; i++) {
          accordion[i].addEventListener("click", function() {

          panel = this.nextElementSibling;

          if (panel.style.maxHeight){
          panel.style.maxHeight = null;
          } else {
          for(j = 0; j < accordion.length; j++) {
          if(j != i) {
          accordion[j].nextElementSibling.style.maxHeight = null;
          accordion[j].classList.remove('active');
          }
          }
          panel.style.maxHeight = panel.scrollHeight + "px";
          }

          this.classList.toggle("active");
          });
          }

          body {
          margin: 0;
          background-color: #e0d9d4;
          }

          .container {
          height: 100%;
          display: flex;
          }

          .about {
          float: left;
          width: 50%;
          color : white;
          background-color : black;
          }

          .projects {
          float : right;
          width : 50%;
          }

          .about h2 {
          font-family: Clearface;
          font-size : 80px;
          padding: 30px;
          }

          .about p {
          font-family: Clearface;
          font-size : 30px;
          padding: 30px;
          }

          .accordion {
          background-color: #333648;
          color: white;
          cursor: pointer;
          padding: 20px;
          width: 100%;
          height: 20%;
          border: none;
          text-align: center;
          outline: none;
          font-size: 17px;
          transition: 0.5s;

          }

          .active, .accordion:hover {
          background-color: #ccc;
          color: black;
          }

          .panel {
          padding:0 18px;
          background-color: white;
          max-height: 0;
          overflow-y: hidden;
          transition: max-height 0.3s ease-out;
          }

          .img-responsive {
          display: block;
          max-width: 100%;
          height: auto;
          margin: 50px auto;
          }

          .header-img-responsive {
          display: block;
          width: 100%;
          height: auto;
          }

          .post {
          padding: 0 20%;
          }

          .title {
          text-align: center;
          color: #932D26;
          }

          <div class="container">
          <div class="about">
          <h2>
          Hello!
          </h2>
          <p>
          Lorem Ipsum är en utfyllnadstext från tryck- och förlagsindustrin. Lorem ipsum har varit standard ända sedan 1500-talet, när en okänd boksättare tog att antal bokstäver och blandade dem för att göra ett provexemplar av en bok. Lorem ipsum har inte bara överlevt fem århundraden, utan även övergången till elektronisk typografi utan större förändringar. Det blev allmänt känt på 1960-talet i samband med lanseringen av Letraset-ark med avsnitt av Lorem Ipsum, och senare med mjukvaror som Aldus PageMaker.
          </p>
          </div>

          <div class="projects">
          <button class="accordion">Project 1</button>
          <div class="panel">
          <div class="post">
          <h2>TITLE HEADING</h2>
          <p>
          Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
          </p>
          <div>
          <img src="images/placeholder.jpg" class="img-responsive">
          <img src="images/placeholder.jpg" class="img-responsive">
          <img src="images/placeholder.jpg" class="img-responsive">
          </div>
          </div>
          </div>

          <button class="accordion">Project 2</button>
          <div class="panel">
          <div class="post">
          <h2>TITLE HEADING</h2>
          <p>
          Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.


          </p>
          <div>
          <img src="images/placeholder.jpg" class="img-responsive">
          <img src="images/placeholder.jpg" class="img-responsive">
          <img src="images/placeholder.jpg" class="img-responsive">
          </div>
          </div>
          </div>

          <button class="accordion">Project 3</button>
          <div class="panel">
          <div class="post">
          <h2>TITLE HEADING</h2>
          <p>
          Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.


          </p>
          <div>
          <img src="images/placeholder.jpg" class="img-responsive">
          <img src="images/placeholder.jpg" class="img-responsive">
          <img src="images/placeholder.jpg" class="img-responsive">
          </div>
          </div>
          </div>

          <button class="accordion">Project 4</button>
          <div class="panel">
          <div class="post">
          <h2>TITLE HEADING</h2>
          <p>
          Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.


          </p>
          <div>
          <img src="images/placeholder.jpg" class="img-responsive">
          <img src="images/placeholder.jpg" class="img-responsive">
          <img src="images/placeholder.jpg" class="img-responsive">
          </div>
          </div>
          </div>

          <button class="accordion">Project 5</button>
          <div class="panel">
          <div class="post">
          <h2>TITLE HEADING</h2>
          <p>
          Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.


          </p>
          <div>
          <img src="images/placeholder.jpg" class="img-responsive">
          <img src="images/placeholder.jpg" class="img-responsive">
          <img src="images/placeholder.jpg" class="img-responsive">
          </div>
          </div>
          </div>
          </div>
          </div>








          share|improve this answer





















          • What to do if I wanted them to keep their height fixed whether they are open or not ?
            – Ramin
            Nov 7 at 21:26













          up vote
          1
          down vote










          up vote
          1
          down vote









          Add display: flex in .container class and add height: 20% in class accordion and it'll work. Check following working code.






          var accordion = document.getElementsByClassName("accordion");
          var i;

          for (i = 0; i < accordion.length; i++) {
          accordion[i].addEventListener("click", function() {

          panel = this.nextElementSibling;

          if (panel.style.maxHeight){
          panel.style.maxHeight = null;
          } else {
          for(j = 0; j < accordion.length; j++) {
          if(j != i) {
          accordion[j].nextElementSibling.style.maxHeight = null;
          accordion[j].classList.remove('active');
          }
          }
          panel.style.maxHeight = panel.scrollHeight + "px";
          }

          this.classList.toggle("active");
          });
          }

          body {
          margin: 0;
          background-color: #e0d9d4;
          }

          .container {
          height: 100%;
          display: flex;
          }

          .about {
          float: left;
          width: 50%;
          color : white;
          background-color : black;
          }

          .projects {
          float : right;
          width : 50%;
          }

          .about h2 {
          font-family: Clearface;
          font-size : 80px;
          padding: 30px;
          }

          .about p {
          font-family: Clearface;
          font-size : 30px;
          padding: 30px;
          }

          .accordion {
          background-color: #333648;
          color: white;
          cursor: pointer;
          padding: 20px;
          width: 100%;
          height: 20%;
          border: none;
          text-align: center;
          outline: none;
          font-size: 17px;
          transition: 0.5s;

          }

          .active, .accordion:hover {
          background-color: #ccc;
          color: black;
          }

          .panel {
          padding:0 18px;
          background-color: white;
          max-height: 0;
          overflow-y: hidden;
          transition: max-height 0.3s ease-out;
          }

          .img-responsive {
          display: block;
          max-width: 100%;
          height: auto;
          margin: 50px auto;
          }

          .header-img-responsive {
          display: block;
          width: 100%;
          height: auto;
          }

          .post {
          padding: 0 20%;
          }

          .title {
          text-align: center;
          color: #932D26;
          }

          <div class="container">
          <div class="about">
          <h2>
          Hello!
          </h2>
          <p>
          Lorem Ipsum är en utfyllnadstext från tryck- och förlagsindustrin. Lorem ipsum har varit standard ända sedan 1500-talet, när en okänd boksättare tog att antal bokstäver och blandade dem för att göra ett provexemplar av en bok. Lorem ipsum har inte bara överlevt fem århundraden, utan även övergången till elektronisk typografi utan större förändringar. Det blev allmänt känt på 1960-talet i samband med lanseringen av Letraset-ark med avsnitt av Lorem Ipsum, och senare med mjukvaror som Aldus PageMaker.
          </p>
          </div>

          <div class="projects">
          <button class="accordion">Project 1</button>
          <div class="panel">
          <div class="post">
          <h2>TITLE HEADING</h2>
          <p>
          Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
          </p>
          <div>
          <img src="images/placeholder.jpg" class="img-responsive">
          <img src="images/placeholder.jpg" class="img-responsive">
          <img src="images/placeholder.jpg" class="img-responsive">
          </div>
          </div>
          </div>

          <button class="accordion">Project 2</button>
          <div class="panel">
          <div class="post">
          <h2>TITLE HEADING</h2>
          <p>
          Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.


          </p>
          <div>
          <img src="images/placeholder.jpg" class="img-responsive">
          <img src="images/placeholder.jpg" class="img-responsive">
          <img src="images/placeholder.jpg" class="img-responsive">
          </div>
          </div>
          </div>

          <button class="accordion">Project 3</button>
          <div class="panel">
          <div class="post">
          <h2>TITLE HEADING</h2>
          <p>
          Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.


          </p>
          <div>
          <img src="images/placeholder.jpg" class="img-responsive">
          <img src="images/placeholder.jpg" class="img-responsive">
          <img src="images/placeholder.jpg" class="img-responsive">
          </div>
          </div>
          </div>

          <button class="accordion">Project 4</button>
          <div class="panel">
          <div class="post">
          <h2>TITLE HEADING</h2>
          <p>
          Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.


          </p>
          <div>
          <img src="images/placeholder.jpg" class="img-responsive">
          <img src="images/placeholder.jpg" class="img-responsive">
          <img src="images/placeholder.jpg" class="img-responsive">
          </div>
          </div>
          </div>

          <button class="accordion">Project 5</button>
          <div class="panel">
          <div class="post">
          <h2>TITLE HEADING</h2>
          <p>
          Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.


          </p>
          <div>
          <img src="images/placeholder.jpg" class="img-responsive">
          <img src="images/placeholder.jpg" class="img-responsive">
          <img src="images/placeholder.jpg" class="img-responsive">
          </div>
          </div>
          </div>
          </div>
          </div>








          share|improve this answer












          Add display: flex in .container class and add height: 20% in class accordion and it'll work. Check following working code.






          var accordion = document.getElementsByClassName("accordion");
          var i;

          for (i = 0; i < accordion.length; i++) {
          accordion[i].addEventListener("click", function() {

          panel = this.nextElementSibling;

          if (panel.style.maxHeight){
          panel.style.maxHeight = null;
          } else {
          for(j = 0; j < accordion.length; j++) {
          if(j != i) {
          accordion[j].nextElementSibling.style.maxHeight = null;
          accordion[j].classList.remove('active');
          }
          }
          panel.style.maxHeight = panel.scrollHeight + "px";
          }

          this.classList.toggle("active");
          });
          }

          body {
          margin: 0;
          background-color: #e0d9d4;
          }

          .container {
          height: 100%;
          display: flex;
          }

          .about {
          float: left;
          width: 50%;
          color : white;
          background-color : black;
          }

          .projects {
          float : right;
          width : 50%;
          }

          .about h2 {
          font-family: Clearface;
          font-size : 80px;
          padding: 30px;
          }

          .about p {
          font-family: Clearface;
          font-size : 30px;
          padding: 30px;
          }

          .accordion {
          background-color: #333648;
          color: white;
          cursor: pointer;
          padding: 20px;
          width: 100%;
          height: 20%;
          border: none;
          text-align: center;
          outline: none;
          font-size: 17px;
          transition: 0.5s;

          }

          .active, .accordion:hover {
          background-color: #ccc;
          color: black;
          }

          .panel {
          padding:0 18px;
          background-color: white;
          max-height: 0;
          overflow-y: hidden;
          transition: max-height 0.3s ease-out;
          }

          .img-responsive {
          display: block;
          max-width: 100%;
          height: auto;
          margin: 50px auto;
          }

          .header-img-responsive {
          display: block;
          width: 100%;
          height: auto;
          }

          .post {
          padding: 0 20%;
          }

          .title {
          text-align: center;
          color: #932D26;
          }

          <div class="container">
          <div class="about">
          <h2>
          Hello!
          </h2>
          <p>
          Lorem Ipsum är en utfyllnadstext från tryck- och förlagsindustrin. Lorem ipsum har varit standard ända sedan 1500-talet, när en okänd boksättare tog att antal bokstäver och blandade dem för att göra ett provexemplar av en bok. Lorem ipsum har inte bara överlevt fem århundraden, utan även övergången till elektronisk typografi utan större förändringar. Det blev allmänt känt på 1960-talet i samband med lanseringen av Letraset-ark med avsnitt av Lorem Ipsum, och senare med mjukvaror som Aldus PageMaker.
          </p>
          </div>

          <div class="projects">
          <button class="accordion">Project 1</button>
          <div class="panel">
          <div class="post">
          <h2>TITLE HEADING</h2>
          <p>
          Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
          </p>
          <div>
          <img src="images/placeholder.jpg" class="img-responsive">
          <img src="images/placeholder.jpg" class="img-responsive">
          <img src="images/placeholder.jpg" class="img-responsive">
          </div>
          </div>
          </div>

          <button class="accordion">Project 2</button>
          <div class="panel">
          <div class="post">
          <h2>TITLE HEADING</h2>
          <p>
          Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.


          </p>
          <div>
          <img src="images/placeholder.jpg" class="img-responsive">
          <img src="images/placeholder.jpg" class="img-responsive">
          <img src="images/placeholder.jpg" class="img-responsive">
          </div>
          </div>
          </div>

          <button class="accordion">Project 3</button>
          <div class="panel">
          <div class="post">
          <h2>TITLE HEADING</h2>
          <p>
          Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.


          </p>
          <div>
          <img src="images/placeholder.jpg" class="img-responsive">
          <img src="images/placeholder.jpg" class="img-responsive">
          <img src="images/placeholder.jpg" class="img-responsive">
          </div>
          </div>
          </div>

          <button class="accordion">Project 4</button>
          <div class="panel">
          <div class="post">
          <h2>TITLE HEADING</h2>
          <p>
          Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.


          </p>
          <div>
          <img src="images/placeholder.jpg" class="img-responsive">
          <img src="images/placeholder.jpg" class="img-responsive">
          <img src="images/placeholder.jpg" class="img-responsive">
          </div>
          </div>
          </div>

          <button class="accordion">Project 5</button>
          <div class="panel">
          <div class="post">
          <h2>TITLE HEADING</h2>
          <p>
          Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.


          </p>
          <div>
          <img src="images/placeholder.jpg" class="img-responsive">
          <img src="images/placeholder.jpg" class="img-responsive">
          <img src="images/placeholder.jpg" class="img-responsive">
          </div>
          </div>
          </div>
          </div>
          </div>








          var accordion = document.getElementsByClassName("accordion");
          var i;

          for (i = 0; i < accordion.length; i++) {
          accordion[i].addEventListener("click", function() {

          panel = this.nextElementSibling;

          if (panel.style.maxHeight){
          panel.style.maxHeight = null;
          } else {
          for(j = 0; j < accordion.length; j++) {
          if(j != i) {
          accordion[j].nextElementSibling.style.maxHeight = null;
          accordion[j].classList.remove('active');
          }
          }
          panel.style.maxHeight = panel.scrollHeight + "px";
          }

          this.classList.toggle("active");
          });
          }

          body {
          margin: 0;
          background-color: #e0d9d4;
          }

          .container {
          height: 100%;
          display: flex;
          }

          .about {
          float: left;
          width: 50%;
          color : white;
          background-color : black;
          }

          .projects {
          float : right;
          width : 50%;
          }

          .about h2 {
          font-family: Clearface;
          font-size : 80px;
          padding: 30px;
          }

          .about p {
          font-family: Clearface;
          font-size : 30px;
          padding: 30px;
          }

          .accordion {
          background-color: #333648;
          color: white;
          cursor: pointer;
          padding: 20px;
          width: 100%;
          height: 20%;
          border: none;
          text-align: center;
          outline: none;
          font-size: 17px;
          transition: 0.5s;

          }

          .active, .accordion:hover {
          background-color: #ccc;
          color: black;
          }

          .panel {
          padding:0 18px;
          background-color: white;
          max-height: 0;
          overflow-y: hidden;
          transition: max-height 0.3s ease-out;
          }

          .img-responsive {
          display: block;
          max-width: 100%;
          height: auto;
          margin: 50px auto;
          }

          .header-img-responsive {
          display: block;
          width: 100%;
          height: auto;
          }

          .post {
          padding: 0 20%;
          }

          .title {
          text-align: center;
          color: #932D26;
          }

          <div class="container">
          <div class="about">
          <h2>
          Hello!
          </h2>
          <p>
          Lorem Ipsum är en utfyllnadstext från tryck- och förlagsindustrin. Lorem ipsum har varit standard ända sedan 1500-talet, när en okänd boksättare tog att antal bokstäver och blandade dem för att göra ett provexemplar av en bok. Lorem ipsum har inte bara överlevt fem århundraden, utan även övergången till elektronisk typografi utan större förändringar. Det blev allmänt känt på 1960-talet i samband med lanseringen av Letraset-ark med avsnitt av Lorem Ipsum, och senare med mjukvaror som Aldus PageMaker.
          </p>
          </div>

          <div class="projects">
          <button class="accordion">Project 1</button>
          <div class="panel">
          <div class="post">
          <h2>TITLE HEADING</h2>
          <p>
          Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
          </p>
          <div>
          <img src="images/placeholder.jpg" class="img-responsive">
          <img src="images/placeholder.jpg" class="img-responsive">
          <img src="images/placeholder.jpg" class="img-responsive">
          </div>
          </div>
          </div>

          <button class="accordion">Project 2</button>
          <div class="panel">
          <div class="post">
          <h2>TITLE HEADING</h2>
          <p>
          Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.


          </p>
          <div>
          <img src="images/placeholder.jpg" class="img-responsive">
          <img src="images/placeholder.jpg" class="img-responsive">
          <img src="images/placeholder.jpg" class="img-responsive">
          </div>
          </div>
          </div>

          <button class="accordion">Project 3</button>
          <div class="panel">
          <div class="post">
          <h2>TITLE HEADING</h2>
          <p>
          Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.


          </p>
          <div>
          <img src="images/placeholder.jpg" class="img-responsive">
          <img src="images/placeholder.jpg" class="img-responsive">
          <img src="images/placeholder.jpg" class="img-responsive">
          </div>
          </div>
          </div>

          <button class="accordion">Project 4</button>
          <div class="panel">
          <div class="post">
          <h2>TITLE HEADING</h2>
          <p>
          Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.


          </p>
          <div>
          <img src="images/placeholder.jpg" class="img-responsive">
          <img src="images/placeholder.jpg" class="img-responsive">
          <img src="images/placeholder.jpg" class="img-responsive">
          </div>
          </div>
          </div>

          <button class="accordion">Project 5</button>
          <div class="panel">
          <div class="post">
          <h2>TITLE HEADING</h2>
          <p>
          Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.


          </p>
          <div>
          <img src="images/placeholder.jpg" class="img-responsive">
          <img src="images/placeholder.jpg" class="img-responsive">
          <img src="images/placeholder.jpg" class="img-responsive">
          </div>
          </div>
          </div>
          </div>
          </div>





          var accordion = document.getElementsByClassName("accordion");
          var i;

          for (i = 0; i < accordion.length; i++) {
          accordion[i].addEventListener("click", function() {

          panel = this.nextElementSibling;

          if (panel.style.maxHeight){
          panel.style.maxHeight = null;
          } else {
          for(j = 0; j < accordion.length; j++) {
          if(j != i) {
          accordion[j].nextElementSibling.style.maxHeight = null;
          accordion[j].classList.remove('active');
          }
          }
          panel.style.maxHeight = panel.scrollHeight + "px";
          }

          this.classList.toggle("active");
          });
          }

          body {
          margin: 0;
          background-color: #e0d9d4;
          }

          .container {
          height: 100%;
          display: flex;
          }

          .about {
          float: left;
          width: 50%;
          color : white;
          background-color : black;
          }

          .projects {
          float : right;
          width : 50%;
          }

          .about h2 {
          font-family: Clearface;
          font-size : 80px;
          padding: 30px;
          }

          .about p {
          font-family: Clearface;
          font-size : 30px;
          padding: 30px;
          }

          .accordion {
          background-color: #333648;
          color: white;
          cursor: pointer;
          padding: 20px;
          width: 100%;
          height: 20%;
          border: none;
          text-align: center;
          outline: none;
          font-size: 17px;
          transition: 0.5s;

          }

          .active, .accordion:hover {
          background-color: #ccc;
          color: black;
          }

          .panel {
          padding:0 18px;
          background-color: white;
          max-height: 0;
          overflow-y: hidden;
          transition: max-height 0.3s ease-out;
          }

          .img-responsive {
          display: block;
          max-width: 100%;
          height: auto;
          margin: 50px auto;
          }

          .header-img-responsive {
          display: block;
          width: 100%;
          height: auto;
          }

          .post {
          padding: 0 20%;
          }

          .title {
          text-align: center;
          color: #932D26;
          }

          <div class="container">
          <div class="about">
          <h2>
          Hello!
          </h2>
          <p>
          Lorem Ipsum är en utfyllnadstext från tryck- och förlagsindustrin. Lorem ipsum har varit standard ända sedan 1500-talet, när en okänd boksättare tog att antal bokstäver och blandade dem för att göra ett provexemplar av en bok. Lorem ipsum har inte bara överlevt fem århundraden, utan även övergången till elektronisk typografi utan större förändringar. Det blev allmänt känt på 1960-talet i samband med lanseringen av Letraset-ark med avsnitt av Lorem Ipsum, och senare med mjukvaror som Aldus PageMaker.
          </p>
          </div>

          <div class="projects">
          <button class="accordion">Project 1</button>
          <div class="panel">
          <div class="post">
          <h2>TITLE HEADING</h2>
          <p>
          Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
          </p>
          <div>
          <img src="images/placeholder.jpg" class="img-responsive">
          <img src="images/placeholder.jpg" class="img-responsive">
          <img src="images/placeholder.jpg" class="img-responsive">
          </div>
          </div>
          </div>

          <button class="accordion">Project 2</button>
          <div class="panel">
          <div class="post">
          <h2>TITLE HEADING</h2>
          <p>
          Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.


          </p>
          <div>
          <img src="images/placeholder.jpg" class="img-responsive">
          <img src="images/placeholder.jpg" class="img-responsive">
          <img src="images/placeholder.jpg" class="img-responsive">
          </div>
          </div>
          </div>

          <button class="accordion">Project 3</button>
          <div class="panel">
          <div class="post">
          <h2>TITLE HEADING</h2>
          <p>
          Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.


          </p>
          <div>
          <img src="images/placeholder.jpg" class="img-responsive">
          <img src="images/placeholder.jpg" class="img-responsive">
          <img src="images/placeholder.jpg" class="img-responsive">
          </div>
          </div>
          </div>

          <button class="accordion">Project 4</button>
          <div class="panel">
          <div class="post">
          <h2>TITLE HEADING</h2>
          <p>
          Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.


          </p>
          <div>
          <img src="images/placeholder.jpg" class="img-responsive">
          <img src="images/placeholder.jpg" class="img-responsive">
          <img src="images/placeholder.jpg" class="img-responsive">
          </div>
          </div>
          </div>

          <button class="accordion">Project 5</button>
          <div class="panel">
          <div class="post">
          <h2>TITLE HEADING</h2>
          <p>
          Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.


          </p>
          <div>
          <img src="images/placeholder.jpg" class="img-responsive">
          <img src="images/placeholder.jpg" class="img-responsive">
          <img src="images/placeholder.jpg" class="img-responsive">
          </div>
          </div>
          </div>
          </div>
          </div>






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 7 at 21:02









          aneo

          134




          134












          • What to do if I wanted them to keep their height fixed whether they are open or not ?
            – Ramin
            Nov 7 at 21:26


















          • What to do if I wanted them to keep their height fixed whether they are open or not ?
            – Ramin
            Nov 7 at 21:26
















          What to do if I wanted them to keep their height fixed whether they are open or not ?
          – Ramin
          Nov 7 at 21:26




          What to do if I wanted them to keep their height fixed whether they are open or not ?
          – Ramin
          Nov 7 at 21:26


















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53197637%2fhow-to-have-accordin-buttons-heights-fill-the-remaining-space-evenly%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          Xamarin.form Move up view when keyboard appear

          Post-Redirect-Get with Spring WebFlux and Thymeleaf

          Anylogic : not able to use stopDelay()