Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing bootstrap grid for print media from col-xs to col-sm

I have a webpage which when printed, needs to follow the col-sm-* grid instead of the col-xs-* grid. Is there a trivial way to achieve this? Can the width of the print preview page be changed, so that it fits all styles for col-sm-* rules?

Here's an example:

window.print();
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />

<div class="row">
  <div class="col-sm-6 col-xs-12">
    <h1>Left column</h1>
  </div>

  <div class="col-sm-6 col-xs-12">
    <h1>Right column</h1>
  </div>
</div>

This is what actually prints:

Actual page that prints

This is what I expect it to print:

Expected print preview

like image 620
John Bupit Avatar asked Sep 29 '15 19:09

John Bupit


1 Answers

You need to use the custom CSS for print that will override the sm in print layouts. This issue has been observed in bootstrap version > 3.0.

@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!important;
}
.col-sm-12 {
  width: 100%;
}
.col-sm-11 {
  width: 91.66666666666666%;
}
.col-sm-10 {
  width: 83.33333333333334%;
}
.col-sm-9 {
  width: 75%;
}
.col-sm-8 {
  width: 66.66666666666666%;
}
.col-sm-7 {
  width: 58.333333333333336%;
}
.col-sm-6 {
  width: 50%;
}
.col-sm-5 {
  width: 41.66666666666667%;
}
.col-sm-4 {
  width: 33.33333333333333%;
}
.col-sm-3 {
  width: 25%;
}
.col-sm-2 {
  width: 16.666666666666664%;
}
.col-sm-1 {
  width: 8.333333333333332%;
}

}

Here's the running snippet of above sample with your code. Click on FullScreen preview and then print it.

like image 194
vendettamit Avatar answered Oct 11 '22 16:10

vendettamit