Set the page-breaking behavior for an element

When printing a web page, sometimes an element should not be printed on two pages. For example, we want a set of questions to be in the same page. At this time, we need set the page-breaking behavior.

CSS code for this is actually very easy:

.pagebreak{
     page-break-before:always;
}

However, to use this function we need to leave enough space for an element, otherwise, it won’t work. This means that there is some space wasting. It’s not hard to understand this, because we want an element stay together, but the current page doesn’t have enough left, so it should be set to the next page.

Leave a Comment