I am trying to do a module where I list orders between dates.
I have set the needed parameters in CSS like this:
#page {
size: A4;
}
#media print {
html, body {
width: 210mm;
height: 297mm;
}
...
}
As header, each page should display the name of the buyer and the order number. I have managed to do this using a DIV having page-break-after: always CSS code after each order. This way each order begins on a new page.
The problem is that when I have too much items in the order and the orders are listed on more then one page. In this case on the second page I don't have the header displayed and I need it.
I have tried to use a div with css attributes like: top:0; position: fixed; but every single header gets displayed on all the pages, which is not good.
UPDATE:
I need the header of the actual order each page of the order. So if I have i.e. 40 items in an order (which does not fit into one page) then I need the header of this order listed on both of its pages.
This is how it works with position:fixed:
After hours of different unsuccessful tries (1. using exact width font like Courier New and calculating the height of each item, 2. using javascript, jquery to see if the bottom of each item exceeds the limit of space for a page, I've put pagebreak, etc...) I have found the best solutions for this here .
If you use
thead {display: table-header-group; }
the header is displayed on each printed page's header. The same is true for tfoot:
tfoot {display: table-footer-group; }
Related
I am currently working in a HTML-editor of a CRM software, so I am limited to HTML and CSS.
Within an invoice there is a table of items, description, amount, price etc. In some cases the description is to long to fit into one page, for example if there are more products. In the beginning the element was just put to the next page. But I wanted to let the description split, so I added:
tr {page-break-inside: auto;}
That works, but on the second page the splitted content is shown in the header of the table.
I tried page-break-inside=avoid; page-break-after=avoid in the tr of the table header and in the styling elemt of the table.
I expected that only the content in the cells is split and not the content of the cells into the table header.
I am looking for a solution to make the table header fixed and avoid overlapping of the splitted content.
I tried to work with these attributes but theader is always overlapping.
table { page-break-inside:auto }
tr { page-break-inside:auto; page-break-after:auto }
thead { display:table-header-group }
This is how the table header looks like:
<thead style='display: table-header-group;';>
<tr style='height:32px;position: relative; z-index: -1;page-break-inside:avoid; page-break-after:auto'>
How do I print a div element so that it is positioned towards the bottom of the page it is on, but is not a footer and is to be printed once only no matter how many pages there are to print (when I set it as a footer it apparently started printing itself on every page)
Also, if there is not enough space on the page to have it printed, it is to jump to the second page.
What it is
I have a div block that is a legend for a table. It describes fields of the table in more detail.
Things I have tried so far
I have tried the fixed footer approach:
#media print {
#legend {
position: fixed;
bottom: 0;
}
}
Somehow it started printing my legend on all pages and not just the first page where I need it. Also when my table is too long, it overlaps the legend. That is not desirable. I am not sure how to proceed.
I seem to be having some success with
#media print :first {
#legend {
position: absolute;
bottom: 0;
}
}
and then programmatically breaking up the table in my code, to where i.e. after row 25 I insert a class into the row to force a page break. Or after row 25 stop this table (</table>), restart a new 2nd one (<table>), which will flow onto the next page
I need to create print version of website, and as I mention in title I need to display site logo just on first page. For example, if I print home page, and I get 5 pages, logo should be displayed just on first page.
is it possible with #media print ?
What I've tried so far but does not work
#media print {
#top-menu,
#main-navigation-sticky-wrapper,
#action-bar,
.teaser-cda,
.pre-footer,
.footer,
.post-footer,
.header .logo {
display: none;
}
#page:first {
.header .logo { display:block }
}
The correct syntax (according to MDN) for first page is:
#page :first {
/* .... */
}
You don't have a space between the two components. Be wary, however, as compatibility for #page :first is not well-defined.
It might not even be necessary though. I don't think block-level elements get repeated on every page, so you might just need to ensure that the logo is displayed in #media print { ... }.
You will also want to check the element and it's container elements to ensure that none of them have position: fixed as that may also cause the element to repeat on each printed page.
#page rule is a CSS at-rule used to modify different aspects of a printed page property. It targets and modifies only the page's dimensions, page orientation, and margins.
It can't have css class inside.
#page :first {...} it just allows you to add these previous styles on the first page but you can't also add a class inside.
So i have this generated page i want to print - http://hubog-2017.com/print_prog_en
I break the page after each table. In the second table, one of the texts is too long and it breaks into two pages (Pages 2 and 3). Now the problem is that the text gets outside its TD and i see it on the THEAD.
I tried using word-breaks and padding's with no success.
Managed to get a partial solution by adding this CSS:
Its not exactly how i wanted it to look but at least the text is not breaking...
#page {
size: A4;
}
#media print {
html, body {
width: 210mm;
height: 297mm;
}
}
I want to give some space to top of every page which is applied in only in printing mode.
is it possible or not..?
I am using:
#page { margin-top : 30px; }
But it doesn't get applied..
Are there any other methods available in css..?
You can do the following way.
#media print
{
body {margin-top:30px;}
}
This will select and target only the print related CSS changes. Hope this helps.
*PS: I have taken Body element, but if you want, you can target specific wrapper that is part of your HTML and you can target it specifically only if you want that wrapper to start from top with certain spacing. You have the solution with logic. Use it to match your scenarios.*