Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

102
Views
Collapsible div pushing down the next row of div

I'm not very good at css but i need to solve some alignment issues with Collapsible div. Below HTML portion is in while loop and I have multiple rows of div and each row has 2 div. When clicking on 1st div on the 1st row it is expanding and pushing down the 1st div of 2nd row which is correct but along with this 2nd div of 2nd row also moving down. enter image description here

<div class="cards">
    <div class="Interview" id="Interview">
        <?php while ($Interview_Details) { ?>
            <div class="card01">
                <div class="collapsible">
                    <div class="image"><img src="<?php echo "/images/people/" . $Interview_Details['Photo']; ?>"/></div>
                    <div class="interview"><?php echo $Interview_Details['shortDesc']; ?>
                    </div>
                </div>
                <div class="content">
                    <p><?php echo $Interview_Details['LongDesc']; ?></p>
                    <div class="padding10">&nbsp;</div>
                </div>
            </div>
        <?php } ?>
    </div>
</div>

.card01{
    width: 47%;
    height: auto;
    position: relative;
    display: inline-block;
    margin-top: 20px;
    vertical-align: top;
    min-height: 220px;
    background: rgb(255, 255, 255);
}
.content {
    max-height: 0px;
    padding: 0px 18px;
    overflow: hidden;
    transition: max-height 0.2s ease-out 0s;
}

<script>
var coll = document.getElementsByClassName("collapsible");
var i;

for (i = 0; i < coll.length; i++) {
    coll[i].addEventListener("click", function () {
        this.classList.toggle("active");
        var content = this.nextElementSibling;
        if (content.style.maxHeight) {
            content.style.maxHeight = null;
        } else {
            content.style.maxHeight = content.scrollHeight + "px";
        }
    });
}
</script>
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Define a class for Expand/Collapse

CSS

.card01 .content {
    height: 0;
    transition: 100%;
}

.card01 .content.active {
    height: auto;
}

Javascript

const cards = document.querySelectorAll("#Interview .card01")

cards.forEach(e => {
    e.addEventListener("click", () => {
        e.classList.toggle("active");

        cards.forEach(el => {
            if (el !== e) el.classList.remove("active");
        });
    });
});
about 4 years ago · Juan Pablo Isaza Report

0

The class card01 can only appear once per column... meaning each column has it's own container. Here is a snippet to see how the HTML should look.

var coll = document.getElementsByClassName("collapsible");
var i;

for (i = 0; i < coll.length; i++) {
    coll[i].addEventListener("click", function () {
        this.classList.toggle("active");
        var content = this.nextElementSibling;
        if (content.style.maxHeight) {
            content.style.maxHeight = null;
        } else {
            content.style.maxHeight = content.scrollHeight + "px";
        }
    });
}
.card01{
    width: 47%;
    height: auto;
    position: relative;
    display: inline-block;
    margin-top: 20px;
    vertical-align: top;
    min-height: 220px;
    background: rgb(255, 255, 255);
}
.content {
    max-height: 0px;
    padding: 0px 18px;
    overflow: hidden;
    transition: max-height 0.2s ease-out 0s;
}
<div class="card01">
  <div class="collapsible">
    <div class="image"><img src="/images/people/" /></div>
    <div class="interview">This is a short description</div>
  </div>
  <div class="content">
    <p>This is a long description. This is a long description. This is a long description</p>
    <div class="padding10">&nbsp;</div>
  </div>
  <div class="collapsible">
    <div class="image"><img src="/images/people/" /></div>
    <div class="interview">This is a short description</div>
  </div>
  <div class="content">
    <p>This is a long description. This is a long description. This is a long description</p>
    <div class="padding10">&nbsp;</div>
  </div>
</div>

<div class="card01">
  <div class="collapsible">
    <div class="image"><img src="/images/people/" /></div>
    <div class="interview">This is a short description</div>
  </div>
  <div class="content">
    <p>This is a long description. This is a long description. This is a long description</p>
    <div class="padding10">&nbsp;</div>
  </div>
  <div class="collapsible">
    <div class="image"><img src="/images/people/" /></div>
    <div class="interview">This is a short description</div>
  </div>
  <div class="content">
    <p>This is a long description. This is a long description. This is a long description</p>
    <div class="padding10">&nbsp;</div>
  </div>
</div>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!