How to find out that a div is not fitted on page for printing

I want to print some shop factors, so within foreach loop, I tried echoing each factor like this:

enter image description here

But let’s say that the 2nd factor which is div2 in this case, has many more items, so if you try to print that, it will collapse the page and goes to the next page for printing!

So I need to determine that if a custom div is going out of the entire page, do not show it at the current and show it at next page instead.

So how to do this?