Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print issue with bootstrap fixed navbar

I've made website with bootstrap fixed navbar. It has fixed navbar so in stylesheet body have top-padding of 70px.

When i print the page it add that extra space at top of paper. What can i do to remove that extra space causing by that top-padding.

Below is print preview with padding

Print Preview of with padding

Below is print preview without padding which i want with less space at top.

enter image description here

If i remove the padding the print is as i want but the in browser the content get behind the nav bar and i can't see the first 2-3 lines.

Please give me some solution to retain the fixed navbar and also the padding don't get include in print.

like image 789
Sumit P Makwana Avatar asked Feb 19 '14 09:02

Sumit P Makwana


3 Answers

Add a new print stylesheet like so (place this after your main stylesheet):

<link rel="stylesheet" href="/css/print.css" media="print">

In print.css set your new CSS rule for the body tag like so:

body {
    margin-top: 0;
}
like image 125
Billy Moat Avatar answered Oct 29 '22 20:10

Billy Moat


I know you may or may not want to show the navbar in print. I wanted to show it, so I added this in my CSS (Bootstrap 3):

@media print { 
    .navbar {
        display: block;
        border-width:0 !important;
    }
    .navbar-toggle {
        display:none;
    }
}
like image 32
blalond Avatar answered Oct 29 '22 21:10

blalond


The accepted answer works perfectly, but if you don't want to add a new style sheet, an alternative is to wrap the body padding in a media tag. In your Site.css:

@media screen {
body {
    padding-top: 50px;
    padding-bottom: 20px;
}

}

This specifies that the style should only be applied when viewing the page, not printing.

like image 37
RobJohnson Avatar answered Oct 29 '22 21:10

RobJohnson