The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Page break problems
Brian Chandler
post Apr 18 2025, 11:47 AM
Post #1


Jocular coder
********

Group: Members
Posts: 2,494
Joined: 31-August 06
Member No.: 43



I'm trying to tidy up my printed invoices (generated in html, because I don't want to do everything all over again). Sometimes these go over one page; each block of invoice information is a div, and I have managed to get the new div to move to the next page with the following:

CODE

DIV.newpage {
    margin-top: 150mm !important;
    break-before: page;
}


However, the margin-top, which is supposed to leave a 15cm margin at the top of the page, has no effect. The new page starts from precisely the top edge of the paper. So how should I go about trying to improve this? One problem is that the meaning of "margin" is not very clear: perhaps css is indeed leaving a 15cm margin, but it is above the paper; who knows. Then I notice that I have also tried using the @page thing (I have been sporadically trying to make this work reliably for >20 years now). Specifically:

CODE

@page {
    margin: 10mm;
}


This appears to have no effect. So I tried "researching", and ended up at W3schools (@page). Is this a mistake? Is there an obvious, Much Better place I should be looking?

The page is not very clear; it lists three properties, including margin, and lists browser support (or mostly not) for a bunch more properties which are not explained. All we learn is that margin is supposed to specify the page margins.

If anyone is prepared to help, I can make a public sample page, but it involves a little bit of work... tks

User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Apr 18 2025, 02:44 PM
Post #2


.
********

Group: WDG Moderators
Posts: 9,806
Joined: 10-August 06
Member No.: 7



I have no idea, unless it's a case of collapsing margins? See https://developer.mozilla.org/en-US/docs/We...rgin_collapsing (but it seems weird that margins on separate printed pages would collapse).
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
coothead
post Apr 18 2025, 07:18 PM
Post #3


Serious Coder
*****

Group: Members
Posts: 257
Joined: 12-January 23
From: chertsey, a small town 25 miles south west of london, england
Member No.: 28,743



Hi there Brian Chandler,

assuming that you are using an external style sheet, then
the code should look something like this...

HTML - head section

CODE
<link rel="stylesheet" href="your-file-name.css" media="screen,print">


your-file-name.css - file

CODE
@media print {
.newpage {
    margin-top: 15em;
    break-before: page;
  }
}



coothead
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Brian Chandler
post Apr 19 2025, 12:51 PM
Post #4


Jocular coder
********

Group: Members
Posts: 2,494
Joined: 31-August 06
Member No.: 43



QUOTE(coothead @ Apr 19 2025, 09:18 AM) *

Hi there Brian Chandler,

assuming that you are using an external style sheet, then
the code should look something like this...

HTML - head section

CODE
<link rel="stylesheet" href="your-file-name.css" media="screen,print">


your-file-name.css - file

CODE
@media print {
.newpage {
    margin-top: 15em;
    break-before: page;
  }
}



coothead


Thanks for the reply. Well, I crawled around with the inspector thingy, and mended it. It turned out I had combined the "receipt" div with the "newpage" div:

CODE

<div class="newpage receipt">


but the margin top settings in the two styles were contradictory (receipt said 0, newpage said 15mm). When I separated the newpage div as a dummy it started working.

Your suggestion only differs from what I had by adding "@media print" and by linking an external stylesheet with media="screen,print". What do these actually mean? (I am using @import.) I can see having different stylesheets for the printed version and the onscreen version, but is not the default that style apply anyway?

And I wonder about the @page thing. Has it died or something?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Brian Chandler
post Apr 19 2025, 12:52 PM
Post #5


Jocular coder
********

Group: Members
Posts: 2,494
Joined: 31-August 06
Member No.: 43



QUOTE(coothead @ Apr 19 2025, 09:18 AM) *

Hi there Brian Chandler,

assuming that you are using an external style sheet, then
the code should look something like this...

HTML - head section

CODE
<link rel="stylesheet" href="your-file-name.css" media="screen,print">


your-file-name.css - file

CODE
@media print {
.newpage {
    margin-top: 15em;
    break-before: page;
  }
}



coothead


Thanks for the reply. Well, I crawled around with the inspector thingy, and mended it. It turned out I had combined the "receipt" div with the "newpage" div:

CODE

<div class="newpage receipt">


but the margin top settings in the two styles were contradictory (receipt said 0, newpage said 15mm). When I separated the newpage div as a dummy it started working.

Your suggestion only differs from what I had by adding "@media print" and by linking an external stylesheet with media="screen,print". What do these actually mean? (I am using @import.) I can see having different stylesheets for the printed version and the onscreen version, but is not the default that style apply anyway?

And I wonder about the @page thing. Has it died or something?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
5 User(s) are reading this topic (5 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 19th May 2025 - 01:13 AM