引导3-打印布局和中断后,每个网格列

如果你举这个例子(点击这里查看: http://www.bootply.com/93816)

<div class="container">
<div class="row">
<div class="col-md-6">Column1</div>
<div class="col-md-6">Column2</div>
</div>
</div>

当您对生成的页面进行打印预览时,它似乎会导致列堆栈/中断(就像移除了浮动一样) ,而不是以通常的网格布局显示它们。

我看了 bootstrap.css 的 @media print部分,没有看到任何与 div相关的内容会导致这种情况发生。

有人知道怎么避免这种情况吗?

73872 次浏览

波金格尔斯的评论让我找到了正确的方向所以我要回答我自己的问题。

使用“ xs”大小的网格列(根据 http://getbootstrap.com/css/#grid-options,这是用于“超小型设备电话(< 768px)”) ,Bootstrap 可以按照预期的方式打印。

<div class="container">
<div class="row">
<div class="col-xs-6">Column1</div>
<div class="col-xs-6">Column2</div>
</div>
</div>

我创建了一个单独的 print.css 并添加了以下内容:

@page {
size: A3;
margin-left: -5cm;
margin-right: -5cm;
}

在 Chrome 中运行良好,但是负边距会杀死 IE。Firefox 似乎并不需要它。我会对另一种方法感兴趣。

解决方案必须在元素上,而不是在页面本身上。您也不应该依赖 col- xs-... ,因为它们适用于小屏幕/设备。

问题是页面本身的像素很小,所以 bootstrap 认为它需要应用 xs 样式。

这个问题不会被 Bootstrap 团队解决,而是与 https://code.google.com/p/chromium/issues/detail?id=273306有关

Bootstrap 解决方案是模糊地记录这种“古怪的”行为 https://github.com/twbs/bootstrap/issues/12078

在我看来,应该有一个 col- 打印-... 设置布局类,以便额外的小型和打印可以共存。

我的临时解决办法如下:

@media print {
[class*="col-sm-"] {
float: left;
}
}

您可以使用 col- print,在我们的示例中,我们使用的是 sm,而不是 xs,因为我们希望 xs 阻止布局,这就是为什么利用这些类来打印不起作用的原因。

基于 Gerard 解决方案,您可以像这样使用 bootstrap Mixin.make-grid () , 所以指纹永远不会变成 xs 大小

@media print {
.make-grid(sm);
}

或者生成的 css (如果你不喜欢少用) :

@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%;
}
.col-sm-pull-12 {
right: 100%;
}
.col-sm-pull-11 {
right: 91.66666667%;
}
.col-sm-pull-10 {
right: 83.33333333%;
}
.col-sm-pull-9 {
right: 75%;
}
.col-sm-pull-8 {
right: 66.66666667%;
}
.col-sm-pull-7 {
right: 58.33333333%;
}
.col-sm-pull-6 {
right: 50%;
}
.col-sm-pull-5 {
right: 41.66666667%;
}
.col-sm-pull-4 {
right: 33.33333333%;
}
.col-sm-pull-3 {
right: 25%;
}
.col-sm-pull-2 {
right: 16.66666667%;
}
.col-sm-pull-1 {
right: 8.33333333%;
}
.col-sm-pull-0 {
right: auto;
}
.col-sm-push-12 {
left: 100%;
}
.col-sm-push-11 {
left: 91.66666667%;
}
.col-sm-push-10 {
left: 83.33333333%;
}
.col-sm-push-9 {
left: 75%;
}
.col-sm-push-8 {
left: 66.66666667%;
}
.col-sm-push-7 {
left: 58.33333333%;
}
.col-sm-push-6 {
left: 50%;
}
.col-sm-push-5 {
left: 41.66666667%;
}
.col-sm-push-4 {
left: 33.33333333%;
}
.col-sm-push-3 {
left: 25%;
}
.col-sm-push-2 {
left: 16.66666667%;
}
.col-sm-push-1 {
left: 8.33333333%;
}
.col-sm-push-0 {
left: auto;
}
.col-sm-offset-12 {
margin-left: 100%;
}
.col-sm-offset-11 {
margin-left: 91.66666667%;
}
.col-sm-offset-10 {
margin-left: 83.33333333%;
}
.col-sm-offset-9 {
margin-left: 75%;
}
.col-sm-offset-8 {
margin-left: 66.66666667%;
}
.col-sm-offset-7 {
margin-left: 58.33333333%;
}
.col-sm-offset-6 {
margin-left: 50%;
}
.col-sm-offset-5 {
margin-left: 41.66666667%;
}
.col-sm-offset-4 {
margin-left: 33.33333333%;
}
.col-sm-offset-3 {
margin-left: 25%;
}
.col-sm-offset-2 {
margin-left: 16.66666667%;
}
.col-sm-offset-1 {
margin-left: 8.33333333%;
}
.col-sm-offset-0 {
margin-left: 0%;
}
}