Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8798847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:11:07+00:00 2026-06-14T00:11:07+00:00

I got a task that I am not sure how best to do it.

  • 0

I got a task that I am not sure how best to do it. So I would like some input or suggestions 🙂

Alright, so here is what I need to do.

I have a page with content being sent to the print (it contains images, and text in divs, p, span, h1, h2, h3, hr, a etc tags). And let’s say it is roughly 1500 pixels high.

I have a container div say 300 by 500 pixels.

I need to take the page with all of the content, and split up that content into the divs.

So:

_______________
|              |
|              |
|              |
|   Content    |
|              |
|              |
|              |
|______________|

Goes into:

_______________
|   Part 1     |
|______________|
|   Part 2     |
|______________|
|   Part 3     |
|______________|
|   Part 4     |
|______________|

But my problem comes with how do I take a giant object of multiple elements on a page and go through it and determine that this div should be cut in half and placed in part 1 and part 2 because it can’t fit in the remaining space in part 1? And how do I determine what is remaining and what isn’t?

My thought was to read the entire contents of the body tag into a variable, looping through each element and adding it to another variable which would have remaining space, I could determine that based on the DOM elements height and width. But I’m not sure if that is the best idea.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T00:11:08+00:00Added an answer on June 14, 2026 at 12:11 am

    If using a brute force type approach is not out of the question, then using something like following should work:

    • Put everything in div 1
    • Start taking things from div 1 into div 2 until div 1 is of the correct size
    • Repeat process for div 2

    An alternative approach would be to loop through each node in the div, summing the total height until it exceeds the limit. At that point, take a step back and start moving the content to the next div, repeating the process.

    If your page has a lot of text in a single text node, then it may be a bit tricky. You would most likely need to implement some kind of system to split text nodes in order to be able to calculate the height of individual text blocks and to be able to split them between divs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a common task that I do with some Activities - downloading data
I've got a build.gradle task that works like a champ on my dev box
I got a task to maintain a c# project, I found some code like
I've got an installation task using InnoSetup which I'm not quite sure how to
I have a XAML form that I would like two independent features threaded out
I have a task that would benefit from the Thread Pool design pattern (many
I got the below Rake Task, that runs one a day to settle some
I am not sure how to perform this task Here is document structure name:
need some advice. I'm doing a project on RoR, and do not sure what
I've got an Ant task that when launched will update the version number in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.