Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to handle the page break with a top margin on the next page? #144

Open
fro opened this issue Dec 14, 2019 · 14 comments
Open

How to handle the page break with a top margin on the next page? #144

fro opened this issue Dec 14, 2019 · 14 comments

Comments

@fro
Copy link

fro commented Dec 14, 2019

Hi,

I'm struggling with something which appear to be simple but which is not.

Objective

I want to create a A4 document where:

  1. All the elements can touch the edge of the page
@page {
  -relaxed-page-size: A4;
  size: A4;
  margin: 0;
}
  1. A new "section" (aka chapter) should break to a new page
.section {
  page-break-before: always;
}
  1. Each new section should have a header and a content
.section {
  .header { ... }
  .content { ... }
}
  1. When a section content is to tall for the page, it should print on the next page, without the header but with a padding and the same border
.section {
  .content {
    -webkit-box-decoration-break: clone;
    border: 1mm solid green;
    padding: 3mm;
  }
}

Issue

The property -webkit-box-decoration-break: clone don't work (but should)

Expected

https://www.w3.org/TR/css-break-3/#valdef-box-decoration-break-clone

box-break

(the right part)


So... is there anyway to fix this -or- to achieve the page-break WITH a padding/border applied?

Thank you so much for your insights

@DanielRuf
Copy link
Contributor

2 This property is only supported for inline elements

@fro
Copy link
Author

fro commented Dec 14, 2019

Thank you @DanielRuf for your fast answer!

My main question is about the proper way to handle the page break with a top margin on the next page, when @page margins are set to 0.

Do you think of any way to do this?

Here's the best I can think of for now:

pug

.section
  .header
    h1 real header
  table.main
    thead
      tr
        th header only for margin
    tbody
      tr
        td
          .aside
            | aside
          .content
            each step in [1, 2, 3, 4, 5, 6, 7, 8, 9]
              p #{step} Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Lorem ipsididunt ut labor veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. 

scss

$page_width: 210mm;
$page_height: 297mm;
$header_height: 66mm;
$aside_width: 37mm;

@page {
  -relaxed-page-width: $page_width;
  -relaxed-page-height: $page_height;
  size: $page_width $page_height;
  margin: 0 0 $footer_height; // need de set this to allow template#page-footer
}

html, body {
  margin: 0;
  padding: 0;
}

.section {
  page-break-before: always;
  width: $page_width;

  .header {
    height: $header_height;
    background-color: blue;
  }

  table.main {
    width: $page_width;
    border-collapse: collapse;
  	border-spacing: 0;
    table-layout:fixed;

    thead tr th {
      width: $page_width;
      background-color: gray;
      padding-bottom: 15mm;
    }

    tbody tr td {
      width: $page_width;
      padding: 0;

      .aside {
        float: left;
        width: $aside_width;
        background-color: green;
      }

      .content {
        float: right;
        width: $page_width - $aside_width;
        background-color: yellow;
      }
    }
  }
}

output

Capture d’écran 2019-12-14 à 11 18 44

@fro
Copy link
Author

fro commented Dec 14, 2019

2 This property is only supported for inline elements

Are you sure of this? Because the documentation says: Applies to: all elements

And I can make it work with <p> elements.

@DanielRuf
Copy link
Contributor

This is described / mentioned in the caniuse tables.

w3 does not cover vendor specific differences / bugs.

Not sure, I did not yet try it.

@DanielRuf
Copy link
Contributor

Doesn't Chrome support it now without the vendor prefix?

@DanielRuf
Copy link
Contributor

DanielRuf commented Dec 14, 2019

For debugging purposes the headless mode of puppeteer can be disabled and prevented that the insfance is closed to see what's happening.

@fro fro changed the title Support of box-decoration-break? How to handle the page break with a top margin on the next page? Dec 14, 2019
@fro
Copy link
Author

fro commented Dec 14, 2019

I've edited the title to reflect the real issue here.

I have tried to make it work with a table thead, but there is to many limitations.

Is there another way to do it with Relaxed?

@fro
Copy link
Author

fro commented Dec 15, 2019

For those who are interested: my solution above using a thead as serious limitations when you fill tbody cell with some content. The page-break simply doesn't apply sometimes or apply but the margin is not keeped.

Well, is there any solution to have keep a margin after a page break?

@fro
Copy link
Author

fro commented Dec 15, 2019

@fro
Copy link
Author

fro commented Dec 16, 2019

@DanielRuf I have tried the headless puppeteer but it is not really helpful.

@DanielRuf
Copy link
Contributor

I think you meant headful. We already use puppeteer.

headless: false

@fro
Copy link
Author

fro commented Dec 16, 2019

Oh, yes sorry 👍

const puppeteerConfig = {
  headless: false,
  ...
}

@frankandrobot
Copy link

Any progress here? I have a similar use case:

  • i have a header with full page bleed
  • when I apply margins to the body, the margin does not propagate correctly on page break

Here's the full-page-bleed header:

image

Here's the body incorrectly applying margins on page break:

image

@DanielRuf
Copy link
Contributor

Any progress here

As you can see there was no further progress.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants