Bootstrap grid for printing
What I did was to manually recreate those columns classes in my print css.
.col-print-1 {width:8%; float:left;}
.col-print-2 {width:16%; float:left;}
.col-print-3 {width:25%; float:left;}
.col-print-4 {width:33%; float:left;}
.col-print-5 {width:42%; float:left;}
.col-print-6 {width:50%; float:left;}
.col-print-7 {width:58%; float:left;}
.col-print-8 {width:66%; float:left;}
.col-print-9 {width:75%; float:left;}
.col-print-10{width:83%; float:left;}
.col-print-11{width:92%; float:left;}
.col-print-12{width:100%; float:left;}
Then I just use those classes like I use bootstrap classes to make my columns for print only. I also created .visible-print
and .hidden-print
to hide/show elements only in the print version.
It still needs some work, but that quick patch helped me a lot.
The Sass version of Fredy31 solution:
@for $i from 1 through 12 {
.col-print-#{$i} {
width: #{percentage(round($i*8.33)/100)};
float: left;
}
}
For Bootstrap 4 (using SASS)
@each $breakpoint in map-keys($grid-breakpoints) {
@include media-breakpoint-up($breakpoint) {
$infix: breakpoint-infix($breakpoint, $grid-breakpoints);
@for $i from 1 through $grid-columns {
@media print {
.col-print#{$infix}-#{$i} {
@include make-col($i, $grid-columns);
}
}
}
}
}
will create
@media print {
.col-print-1 {
flex: 0 0 8.33333%;
max-width: 8.33333%; } }
@media print {
.col-print-2 {
flex: 0 0 16.66667%;
max-width: 16.66667%; } }
@media print {
.col-print-3 {
flex: 0 0 25%;
max-width: 25%; } }
@media print {
.col-print-4 {
flex: 0 0 33.33333%;
max-width: 33.33333%; } }
@media print {
.col-print-5 {
flex: 0 0 41.66667%;
max-width: 41.66667%; } }
@media print {
.col-print-6 {
flex: 0 0 50%;
max-width: 50%; } }
@media print {
.col-print-7 {
flex: 0 0 58.33333%;
max-width: 58.33333%; } }
@media print {
.col-print-8 {
flex: 0 0 66.66667%;
max-width: 66.66667%; } }
@media print {
.col-print-9 {
flex: 0 0 75%;
max-width: 75%; } }
@media print {
.col-print-10 {
flex: 0 0 83.33333%;
max-width: 83.33333%; } }
@media print {
.col-print-11 {
flex: 0 0 91.66667%;
max-width: 91.66667%; } }
@media print {
.col-print-12 {
flex: 0 0 100%;
max-width: 100%; } }
If you want the Bootstrap's grid do not print with col-xs (mobile settings) , and want to use col-sm-?? instead , Based on Fredy31 answer and you don't even need to define col-print-??. simply rewrite all col-md-?? css class definitions inside a: @media print { /* copy and paste from bootstrap.css*/ } like this:
@media print {
.col-sm-1, .col-sm-2, .col-sm-3, .col-sm-4, .col-sm-5, .col-sm-6, .col-sm-7, .col-sm-8, .col-sm-9, .col-sm-10, .col-sm-11, .col-sm-12 {
float: left;
}
.col-sm-12 {
width: 100%;
}
.col-sm-11 {
width: 91.66666667%;
}
.col-sm-10 {
width: 83.33333333%;
}
.col-sm-9 {
width: 75%;
}
.col-sm-8 {
width: 66.66666667%;
}
.col-sm-7 {
width: 58.33333333%;
}
.col-sm-6 {
width: 50%;
}
.col-sm-5 {
width: 41.66666667%;
}
.col-sm-4 {
width: 33.33333333%;
}
.col-sm-3 {
width: 25%;
}
.col-sm-2 {
width: 16.66666667%;
}
.col-sm-1 {
width: 8.33333333%;
}
}