There is no good general solution. As some have pointed out, you can put a page break before <div> "B" ... but there you will always get it. Even when "A" and "B" all fit on one page.
You can use page-break-inside="avoid" on <div> "B". This is probably closer to what you want. If "B" does not fit on the page with "A", "B" will all be moved to the next page.
BUT ... that has a side effect because there is a third possibility. What if the content of "B" is so large that it itself does not fit on a page? WHat will happen is that it would do what you think, moving "B" to the next page and try to build that page with "B". It will not be able to meet the condition that "B" avoid a page break inside so it will break that condition. Unfortunately, it would not figure that out until the end of the page, so you will end up with a blank page.
If you know that "B" will always fit on one page, then you can use page-break-inside="avoid" and that would work. But if it does not, nothing will work for you.
A slightly more lengthy explanation for a similar question is here:
HTML/CSS: empty page + only header page when printing table
So what you actually want is three things in one... (1) you would like it avoid a page-break inside as long as it is not longer than a page, otherwise, (2) you want a page break before (3) unless it fits on the current page. Unfortunately, this does not exist. You could only do that with Javascript. You could set the width for the page for the div's and then get the height of div "A" and div "B" and then make a decision to dynamically insert those CSS properties as part of the print process.
You might want to use some print stylesheet with cm
or pt
units for your elements, so you can adjust their physical size printed on paper.
I'd suggest you have a look at this Post:
How To Set Up A Print Style Sheet
I want the div to move left to right on scroll. Which I did. But, how do I make the div go to the right much faster? Because the speed of the div going from left to right is the same as the ...
I want the div to move left to right on scroll. Which I did. But, how do I make the div go to the right much faster? Because the speed of the div going from left to right is the same as the ...
I have this custom jQuery function : jQuery.fn.extend({ disable: function () { return $(this).each(function () { // function code }); } }); When I do something ...
I have this custom jQuery function : jQuery.fn.extend({ disable: function () { return $(this).each(function () { // function code }); } }); When I do something ...
When using fullscreen image gallery and blending between pictures, some images are much bigger and takes some time to load and show up. Yes, there is a function called onload which is called when ...
When using fullscreen image gallery and blending between pictures, some images are much bigger and takes some time to load and show up. Yes, there is a function called onload which is called when ...
Can nested HTML list items be forced to be aligned to the left? for eg: Bat Cat Ratonetwothree Mat <ul> <li>Bat</li> <li>Cat</li> <li>...
Can nested HTML list items be forced to be aligned to the left? for eg: Bat Cat Ratonetwothree Mat <ul> <li>Bat</li> <li>Cat</li> <li>...