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

184
Views
find number of child divs which can fit into parent divs

I have the following scenario: I have an API which returns multiple div's. And in my UI, I have one parent div in which i need to show these div's. The condition is, if child div is overflowing parent, I need to show them on next page.

For eg: lets say my API is returning string like this:

<div class="ab0"></div>
<div class="ab1"></div>
<div class="ab2"></div>
<div class="ab3"></div>
<div class="ab4"></div>

and the parent div can fit in only ab0, ab1, ab2. Then I want to show these 3 div's 1st and when user click on '>' symbol I need to show ab3, ab4. Also if ab2 is partially overflowing and if I can show only overflowing part on next page, that will be great.

Is there any way I can do this.

Thanks in advance

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

A simple suggestion is to use the system's scroll functionality.

The system 'knows' how much it can show at once and as long as you can find out the height of the parent div you can move up and down the children (or part children if an exact number don't fit into the parent at once) using Javascript scrollTop.

const parent = document.querySelector('.parent');
const h = parent.offsetHeight;
let page = 0;
const lastPage = Math.floor((parent.scrollHeight + 1) / h);

function next() {
  if (page < lastPage) {
    page++;
    parent.scrollTop = parent.scrollTop + h;
  }
}

function prev() {
  if (page > 0) {
    page--;
    parent.scrollTop = parent.scrollTop - h;
  }
}
.parent {
  height: 64px;
  overflow: auto;
}

.parent div {
  height: 2em;
  border: 1px solid;
  position: relative;
}

button {
  font-size: 2em;
}
<div class="parent">
  <div class="ab0">0</div>
  <div class="ab1">1</div>
  <div class="ab2">2</div>
  <div class="ab3">3</div>
  <div class="ab4">4</div>
</div>
<button onclick="prev();"><</button>
<button onclick="next();">></button>
</button>

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!