• 0

HTML, CSS - Page breaks


Question

Hey,

Was wondering if there is a way to use html and css to use page breaks when printing?

For example, i have a payroll to be printed, contains 400 staff, each staff member has a table filled with theres hours etc etc, but i dont want it so there will be a table that is split over 2 pages,

How can i do this?

Cheers, Tim

Link to comment
https://www.neowin.net/forum/topic/795962-html-css-page-breaks/
Share on other sites

7 answers to this question

Recommended Posts

  • 0

Assuming something like:

?
<h1>Johny McJanitor</h1>
<table summary="hours johny worked this week" class="hours">
?
</table>

<h1>Susan Q. Sciencelady</h1>
<table summary="hours that susan worked this week" class="hours">
?
</table>

h1 {
  page-break-before:always;
}

or

table.hours {
  page-break-after:always;
}

Obviously if you have a 30,000 line table there's pretty much nothing you can do to stop it from spanning several pages.

Keep in mind that this code in an @media="print" stylesheet and that cross-browser printing is a crap shoot at best. If you have a very specific layout that you need you're best served by creating a PDF server-side and sending that to the user to print. If you aren't too particular about layout then CSS can fill the job just fine.

  • 0

@media print {
  table {
	page-break-inside:avoid;
  }
}

The above should work but support is pretty much non-existent and unpredictable.

The only way I could see to make it work reliably would be to do something like count the number of table rows/captions/etc. figure out how many should fit on a page, and then use javascript to assign a class to tables and force a page-break where you need them.

  • 0

Luckily for me, this part of site is for me and few select admins, all using either latest version of firefox or internet explorer, so hopefully compatabilty should not be a problem,

Cant get your new idea to work though, here is my css code at the moment for the table:

table.payrolltables{

	page-break-after: always;
	page-break-inside:avoid;

}

But it dosent work, just provides each table on new page, Instead of just putting a page split when a table comes that will be split,

How should it be written?

Cheers, Tim

  • 0
  Quote
Luckily for me, this part of site is for me and few select admins, all using either latest version of firefox or internet explorer, so hopefully compatabilty should not be a problem,

When I said support was non-existent and unpredictable I meant "busted to the point of unusable". I've read that Opera supports it and that's about it.

  timsweb said:
table.payrolltables{

page-break-after: always;

}

That says "before you print this element always put a page break" so you'd drop that entirely.

  Quote
How should it be written?

table.payrolltables{
	page-break-inside: avoid;
}

  • 0

That's pretty much expected: support for page-break-inside is almost non existent.

Some sort of javascript row counter that sets page breaks on your tables or just building a PDF server side is going to be the only way to accomplish this. It sucks, but that's the way CSS print support is for the time being.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • From a quick Google it seems 6GHz is optional on 802.11be. Ubiquiti has one, Unifi U7 Lite.
    • Disagreed, I feel it’s going somewhere and his role served a purpose - and moreover with maybe what 10 mins of screen time - he had a bit of character development also.
    • This is the Superman film I had been waiting for. The tone was fine, yes a little more “fun” than previous outings but a lot of that came from supporting characters. Krypto was well handled, and somehow managed to not be an annoying distraction and actually a valid part of the story. Hoult was GREAT as Luthor. Genuinely so happy that this wasn’t crap. I personally enjoyed Superman Returns, despite its flaws (tried too much to hide behind the older movies, had no real fight to Superman). I enjoyed the Man Of Steel movies despite their flaws (totally that is NOT Superman). But this - this is the film I had wanted. In the UK we are far more reserved in cinemas than Americans. It’s rare that there is the whooping and hollering that we have seen from videos of US theatres, so when I say that the audience clapped at the end of this - it’s quite a big deal. As for all this “Superman has gone woke” BS - he is freaking Superman and if at any point in that movie you found yourself pooh-pooing his actions, you are just - you’re aligning your thinking with the problems and not the solutions. I adore how the movie addressed the modern world through thinly veiled allegory (Israel, online bots, perceptions of people, how they change on a dime) - that is maybe one of the greatest strengths of  comics, they rarely pull punches with that sort of thing, and look, THIS IS SUPERMAN, he’s meant to be the global boyscout and that is a strength and where he falls down sometimes, that’s just who he is and who he is meant to be. I also am glad there was no reference to the worldwide joke that is “Truth, Justice and the American way”. I can understand the comment suggesting this film was a little too “fun” or “whimsical”, but I’d urge a rewatch of the Donner Superman. It was very much a flawed masterpiece and its subsequent sequel had too many jokes that didn’t land. While there was a lot of James Gunn in this movie, I feel he pulled it back significantly, it wasn’t Guardians and moreover a lot of the fun came from supporting roles.
    • People do it everywhere. Should be legal to be allowed to bitch slap people who put their phone on speaker in public places
  • Recent Achievements

    • One Month Later
      Ricky Chan earned a badge
      One Month Later
    • First Post
      leoniDAM earned a badge
      First Post
    • Reacting Well
      Ian_ earned a badge
      Reacting Well
    • One Month Later
      Ian_ earned a badge
      One Month Later
    • Dedicated
      MacDaddyAz earned a badge
      Dedicated
  • Popular Contributors

    1. 1
      +primortal
      504
    2. 2
      ATLien_0
      207
    3. 3
      Michael Scrip
      205
    4. 4
      Xenon
      141
    5. 5
      +FloatingFatMan
      115
  • Tell a friend

    Love Neowin? Tell a friend!