HTML Header and footer in all pages while printing html document - html

I've created a html page with a header,some content and a footer. I tried to get a print of the HTML page, and there was 2 pages. I got the header in first page and the footer in the last page.
What i really need is the header and footer to show in all the pages like in a word document.
I checked and found that using the table format with the thead and tfoot,it can be done.
It worked in firefox and IE, but it's not working in chrome. Is this some webkit browser compatibility problem??
Is there any other way which is compatible with all browsers.
Update: As of April 2021, the bug is still open https://bugs.webkit.org/show_bug.cgi?id=17205. as mentioned below by SHAKU here https://stackoverflow.com/a/34884220/2776433

You can target print styles specifically with the "#print" css media style definition. This will allow you to create individual styles strictly for when the document is being printed, and in print preview.
I would start with this as a solid base.
#media print {
* {
color: #000 !important;
-webkit-text-shadow: none !important;
text-shadow: none !important;
font-family: "Times New Roman", Times, serif;
background: transparent !important;
-webkit-box-shadow: none !important;
box-shadow: none !important;
border: none!important;
font-weight: normal!Important;
}
header, nav, footer {
overflow:visible;
}
.body {
width: auto;
border: 0;
margin: 0 5%;
padding: 0;
float: none !important;
}
a, a:link, a:visited {
&[href]:after {
content: " (" attr(href) ") ";
font-size: 90%;
}
&[href^="javascript:"],
&[href^="#"] {
&:after {
content: "";
}
}
}
abbr[title]:after {
content: " (" attr(title) ")";
}
pre,
blockquote {
border: 1px solid #999;
page-break-inside: avoid;
}
thead {
display: table-header-group;
}
tr,
img {
page-break-inside: avoid;
}
img {
max-width: 100% !important;
}
#page {
margin: 0.5cm;
}
p,
h2,
h3 {
orphans: 3;
widows: 3;
}
h2,
h3 {
page-break-after: avoid;
}
}

Use fixed positioned elements that you activate with print media type:
#header, #footer {
display: none;
}
#media print
{
#header, #footer {
position: fixed;
display: block;
top: 0;
}
#footer {
bottom: 0;
}
}
(Here assuming you have div elements with id header and footer).

I had the same problem and found simple tags to work best for me.
<table>
<thead>
<tr><td>
content that should be printed as page header
</td></tr>
</thead>
<tbody>
<tr><td>
content that will be spread over all pages consecutively
</td></tr>
</tbody>
</table>
The table will look like a simple table in the browser, but in printouts the content of the <thead> tag is repeated on each page. No CSS required.
Tested in Firefox 32, IE 11 and even in MS Word 2010. Word does not translate the tag into "real" page headers, but repeats the content on top of each page. (You may have to switch to "Page View" to actually see the difference in Word).

none of the above answers are not really the answer for the question asked. From my experience there is no single clean solution right now available. Feel like chrome is purposefully avoiding this bug. https://bugs.webkit.org/show_bug.cgi?id=17205.

Related

How to print a webpage twice on the same A4 Sheet?

I want two printed copies of the invoice on the same A4 sheet. Is there anyway to achieve the same? It is guaranteed that the single print of the invoice(aka html table in my case), will not exceed more than half of the A4 sheet.
If I understood your question correctly, your .html file that will print out 2 invoices on an A4 page will first need to be prepared as an .html/.php file ( webpage ) and then printed.
I will also assume, you have created a dynamic page that pulls the data into the invoice.
/** style.css **/
.invoice {
margin-top: 2em;
}
span {
color: blue;
border: 1px solid black;
}
.extra span {
color: inherit;
}
#media print {
body{
width: 21cm;
height: 29.7cm;
margin: 20mm; /* Adjust margin as you like. */
}
* {background: transparent !important; color: black !important; text-shadow: none !important; filter:none !important; -ms-filter: none !important} /* Black prints faster */
pre, blockquote {border: 1px solid #999; page-break-inside: avoid; }
thead {display: table-header-group; } /* Repeat header row at top of each printed page */
tr, img {page-break-inside: avoid; }
img {max-width: 100% !important; }
#page {margin: 0.5cm}
p, h2, h3 {orphans: 3; widows: 3}
h2, h3{page-break-after: avoid}
}
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div class="invoice">
Here is <span>First invoice table format</span>
</div>
<div class="invoice extra" style="color:green">
Here is <span>Second invoice table format</span>.
</div>
</body>
</html>

Chrome css print styles leaves text overlapping

We have been working on a new calendar interface which includes a printable "classic" calendar view. There was much working going into the #media print stylesheet, and while everything is looking great in Safari, the event times are overlapping the event name in Chrome. Cannot figure out why.
#media print {
body{
-webkit-print-color-adjust:exact;
}
img,
.calendar-nav button,
.calendar-date-picker,
.event .btn-group {
display: none;
}
.calendar-nav {
text-align: center;
padding-top:20px;
}
.calendar-nav .date-title {
font-size: 50px;
font-weight: normal;
}
a:link:after,
a:visited:after {
content: "";
}
#calendarTable div.event {
padding: 0;
margin-left:0;
text-indent: 0;
}
.events.active {
width: 100%
}
}
EDIT: I fixed the overlap issue by adding .event-location {float: none; margin-top: 0px;} into the print media query.
Also, in Firefox there is a huge margin to the left of the content:
It is pretty hard debugging these print style sheet to figure out what is going on. Even Chrome developer tools will show the correct print preview, but doing a real print shows it incorrect.
Any ideas on what to do to fix these issues? Is using an #media print inside of our main style sheet an issue?
http://www.puc.edu/calendar?state=full
Looks like adding a few styles to overwrite the Bootstrap defaults was all I needed:
.event-location {
float: none !important;
margin-top: 0px !important;
}
.event-time {
float: none !important;
}
body .container {
width:100% !important;
margin:0 !important;
}

Bootstrap Layout Too Wide on Smart Phone

I'm trying to come up with an HTML/CSS layout for mobile devices. (It will likely be a separate website just for mobile devices, but I may be able to get away using a responsive site for both.)
I'm using Bootstrap, and found a layout that I'm implementing. You can see it at http://softcircuits.com/MediCorp/Menus.htm.
The problem is, when I load this page on my Android device (LG G2), the page is slightly wider than my display. So I can view the right side of the page only by scrolling horizontally.
I tried changing all of the container references to instead use container-fluid but it made no difference.
Does anyone know how I can make this page fit my device?
UPDATE:
Steven Wave has been helpful. He suggested some CSS to allow word wrapping. But A) the table still doesn't fit on my LG G2 (1080 x 1920 display), and B) why on Earth is word wrapping prevented by Bootstrap in the first place? Isn't Bootstrap responsive designed to work on cell phones?
Ok so here my last suggetion :)
Overrule again the default bootstrap attributes like:
#media screen and (max-width: 767px){
.table-responsive>.table>thead>tr>th, .table-responsive>.table>tbody>tr>th,
.table-responsive>.table>tfoot>tr>th, .table-responsive>.table>thead>tr>td,
.table-responsive>.table>tbody>tr>td, .table-responsive>.table>tfoot>tr>td {
word-break: break-word;
}
}
and you will be able to achieve your goal.
But i think this is a confusing table and it is not very readable. Because of this bootstrap decided to use the horizontal scrolling behavior. Just for readability.
Update Scaling:
There a several ways you can "scale".
CSS 3 transform: scale(x,y)
With several plugins to manipulate fontsizes eg.
Media Queries
In your case i would decide to use Media Queries so i manipulated your updated site with the Developer Tools
First i added ÌD's to the tables so i can easely overrule bootstrap and dont care about specificity.
<div class="container table-responsive">
<p>....</p>
<table class="table" id="tableA">....</table>
<table class="table table-striped table-condensed" id="tableB">....</table>
</div>
Then i created specific media queries for the points where the table widths become bigger then the viewport.
#media (max-width: "500px") {
#tableB td, #tableB th {
padding: 5px 2px;
font-size: 12px;
}
}
#media (max-width: "400px") {
.container {
padding-right: 5px;
padding-left: 5px;
}
#tableB td, #tableB th {
padding: 5px 2px;
font-size: 12px;
}
}
#media (max-width: "450px") {
#tableA td {
padding: 5px 2px;
font-size: 12px;
}
}
#media (max-width: "350px") {
#tableA td {
padding: 5px 1px;
font-size: 10px;
}
}
In this scenario it's all about space so i reduced the .container attributes as well go get more space.
Now you can resize your site down to 290px (whitch is absolutely ok - most mobile devices are now coverd) and the tables fit to the with.
275px!!
The tabel headers of the second table are very close together but it's also ok i think.
290px!!
Ok know the font-size is smal but there is also the posibility the scale the content trough the smartphone.
Hope that will help!
The problem comes up with your table! You can resolve this with adding the table-responsive attribute to your 'container' div which includes both tables!!
UPDATE:
<div class="container table-responsive">
<p>....</p>
<table class="table">....</table>
<table class="table table-striped table-condensed">....</table>
</div>
A better way is to wrapp only the tables and not the hole content!
Have a look at the bootsrap DOCUMENTATION
UPDATE:
Here the final bootstrap specific solution:
<div class="container">
<p>....</p>
<div class="table-responsive">
<table class="table">....</table>
</div>
<div class="table-responsive">
<table class="table table-striped table-condensed">....</table>
</div>
</div>
This will avoid the empty space at the second table. In general the bootstrap responsive table is fluid as long as the td content does not fill the space. When the content is longer then the horicontal scrolling for the table appears. This is the typical behavior!
If you realy DON'T want that you should go a nother way! Thera are plenty of diffrent solutions for responsive tables out there like THIS
Maybe you find one that fitts your needs!
Overrule the bootsrap attributes from white-space: nowrap; to normal:
#media screen and (max-width: 767px)
.table-responsive>.table>thead>tr>th,
.table-responsive>.table>tbody>tr>th,
.table-responsive>.table>tfoot>tr>th,
.table-responsive>.table>thead>tr>td,
.table-responsive>.table>tbody>tr>td,
.table-responsive>.table>tfoot>tr>td {
white-space: normal;
}
So the tables fit down to 430px. For all smaler devices the scrolling appears.
for positioning example :
<div class="col-sm-12">
<div class="col-sm-6">
column 1
</div>
<div class="col-sm-6">
column 2
</div>
</div>
can use this for tr and td also
Here is solution that change N-columns table to list of properties for screen that width is less than 1000px:
<style>
#media only screen and (max-width: 1000px) {
#userManageTable {
margin-top: 16px;
}
#userManageTable, #userManageTable thead, #userManageTable tbody,
#userManageTable th, #userManageTable td, #userManageTable tr {
display: block;
}
/* Hide table headers (but not display: none;, for accessibility) */
#userManageTable thead tr {
position: absolute;
top: -9999px;
left: -9999px;
}
#userManageTable tbody tr {
border: 1px solid #ccc;
}
#userManageTable tbody td {
/* Behave like a "row" */
border: none;
border-bottom: 1px solid #eee;
position: relative;
padding-left: 50%;
height: 49px;
width: 100%;
}
#userManageTable tfoot {
width: 100%;
}
#userManageTable tfoot td {
/* Behave like a "row" */
border: none;
position: relative;
height: 49px;
width: 100%;
}
#userManageTable tbody td:before {
/* Now like a table header */
position: absolute;
/* Top/left values mimic padding */
top: 6px;
left: 6px;
width: 45%;
padding-right: 10px;
white-space: nowrap;
}
/*
Label the data
*/
#userManageTable tbody td:nth-of-type(1):before {
content: "Imię";
}
#userManageTable tbody td:nth-of-type(2):before {
content: "Nazwisko";
}
#userManageTable tbody td:nth-of-type(3):before {
content: "Login";
}
#userManageTable tbody td:nth-of-type(4):before {
content: "Aktywność";
}
#userManageTable tbody td:nth-of-type(5):before {
content: "";
}
#userManageTable tbody td:nth-of-type(6):before {
content: "";
}
#userManageTable tbody td:nth-of-type(7):before {
content: "";
}
#userManageTable tbody td:nth-of-type(8):before {
content: "";
}
#userManageTable tbody td:nth-of-type(9):before {
content: "";
}
#userManageTable tbody td:nth-of-type(10):before {
content: "";
}
}
</style>
It works with default Bootstrap v.3 CSS.
Just give it id = "userManageTable".

any css after this code not working , what is the problem in this css code, only in firefox?

Footer css after form's css is not working , what is the problem in this css code?
/*------------------------------------*\
FORMS */
fieldset { padding: 10px; border: 1px solid #ccc; margin-bottom: 1.5em; }
label { display: block; cursor: pointer; }
label:after { content:\": "; }
label::after { content:\": "; }
input,textarea { font-family: inherit; font-size: 1em; line-height: 1.5; }
[placeholder] { cursor: pointer; }
[placeholder]:active,[placeholder]:focus { cursor: text; }
fieldset > :last-child { margin: 0; }
footer {background:red; height:200px; width:200px}
jSfiddle http://jsfiddle.net/Aw239/
in jsfiddle example footer should be red background.
At least firefox Doesnt seem to understand this label:after { content:\": "; } i have no idea whats going on here but all i know is that it is the culprit. I've never actually used content properly.
But, remove those lines and everything runs smoothly.. ( OR reformat those two lines as Kyle showed and it should do it. )
Seems like it doesnt like to have closing semicolons in the same row with everything else
http://jsfiddle.net/Aw239/3/
Or.. get rid of the \'s ?
I formatted your CSS a bit and it seems to work in my FF5. http://jsfiddle.net/Aw239/2/
It is red. Are you using IE8? Because you'll need to use the HTML5 shim if you want to style HTML5 elements.
Does this work for you?

Multi-Page invoice printing on one page

I have an invoice that contains over 100 lines of product that I am trying to print. This single invoice should take over 3 pages, but when printed, the content flows off the footer and the next page is the following invoice.
I am using divs instead of tables, and I can't understand why the long invoices will not print on multiple pages.
Any ideas?
Here's my stylesheet:
h1,h2,h3 { margin: 0 0 0.5em 0; padding: 0;}
body { font-family: sans-serif; font-size: 0.8em; }
label, legend { font-weight: bold; }
pre { font-family: sans-serif; }
shipping_address {
width: 45%;
}
billing_address {
width: 45%;
}
order_info {
padding: 0 10px;
}
shipping_logo {
width: 115px;
}
content {
margin: 0px auto 0px auto;
width: 100%;
padding-bottom:15px;
}
div.container {
display: table;
width: 100%;
}
div.header {
display: table-row;
text-align: center;
}
div.row {
display: table-row;
}
.even {
background: #CCCCCC none repeat scroll 0 0;
}
div.cell {
display: table-cell;
padding: 0 10px;
}
You might want to specify specific stylesheets for printing. For example,
#media all
{
.page-break { display:none; }
}
#media print
{
.page-break { display:block; page-break-before:always; }
}
You can then apply the page-break class where you want to page to break. This article has a few neat tricks to format a page for printing.
We're going to need much more information than what you have suggested to really tackle this problem.
However, a pretty blind stab at something that would cause a similar behavior is if you had something set such that the height is 100%, whether it's a table, a div, or something. This is sometimes done to try and keep a footer at the bottom of the browser window and if you do that, this can cause this behavior when printing.