正确打印 Twitter Bootstrap [英] Printing Twitter Bootstrap correctly

查看:22
本文介绍了正确打印 Twitter Bootstrap的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的很难正确打印我的 Twitter Bootstrap 视图,并且想知道是否有人可以为我指明正确的方向.我添加了一个自定义的print.css",它覆盖了一些原始的引导程序样式,以及我自己的一些组件的样式.

这是我的打印对话框:

不确定您是否可以从图像中如此轻松地分辨出来,但是井已经失去了背景并且没有跨越整个页面宽度.此外,列"或跨度"似乎都很不稳定.页面是这样构建的:(只显示第一行以保持干净)

<div class="row-fluid"><div class="span3"><div class="row-fluid"><div style="height: 150px; width: 300px"><img class="img-rounded" src='data:image/png;base64,@Model.Unit.Image64'/>

<div class="row-fluid">...

<div class="span4">...饼图控件

<div class="span5">...条形图控件

这是我的print.css:

@media 打印 {身体 {边距:0;填充:0;行高:1.4em;字间距:1px;字母间距:0.2px;字体:13px Arial、Helvetica、Lucida Grande"、衬线;颜色:#000;}#print-btn #update-btn #nav-left #nav-bar, #selectUnitContainer, .navbar, .sidebar-nav {显示:无;}#print-btn, #update-btn, #units {显示:无;}#导航左{显示:无;}#报告容器{可见性:可见;}.well .span12{宽度:100%;可见性:可见;}.导航栏{显示:无;}.sidebar-nav {显示:无;}}

解决方案

首先 Bootstrap.css 确实带有 预定义的打印样式 如:

/*** 使用这些来切换打印内容.**/.visible-print {显示:阻止!重要;}.隐藏打印{显示:无!重要;}

其次您可以使用 page-break css rule 将图表分隔到不同的页面上,以实现更清晰的格式.

/*** Page-break-inside 似乎* 是 Chrome 所必需的.**/div.somechart {分页后:总是;page-break-inside:避免;}

第三测试使用行进行格式化以占据打印屏幕上的全宽,而不是依赖于的百分比span3/col-*-3span4/col-*-4 的,因为看起来它们当您考虑以下因素时,在某些方面的行为是正确的:

最后最后一个需要注意的事情(是的,尽管有自定义的@print样式!):

到:

I'm really struggeling to print my Twitter Bootstrap views correctly, and was wondering if anyone could point me in the right direction. I've added a custom "print.css" which overrides some of the original bootstrap styling, as well of styling some of my own components.

This is my print dialog:

Not sure if you can tell so easily from the image, but the well has lost its background as well as not spanning across the entire page width. Also, the 'columns' or 'spans' seem to be all wonky. Page is built up like this: (Only showing first row to keep it clean)

<div class="container-fluid">
    <div class="row-fluid">
        <div class="span3">
            <div class="row-fluid">
                <div style="height: 150px; width: 300px">
                    <img class="img-rounded" src='data:image/png;base64,@Model.Unit.Image64' />
                </div>
            </div>

            <div class="row-fluid">
                ...
            </div>

        </div>
        <div class="span4">
            ...Pie chart control
        </div>
        <div class="span5">
            ...Bar chart control
        </div>

    </div>
</div>

Here's my print.css:

@media print {
    body {
        margin: 0;
        padding: 0;
        line-height: 1.4em;
        word-spacing: 1px;
        letter-spacing: 0.2px;
        font: 13px Arial, Helvetica,"Lucida Grande", serif;
        color: #000;
    }

    #print-btn #update-btn #nav-left #nav-bar, #selectUnitContainer, .navbar, .sidebar-nav {
        display: none;
    }

    #print-btn, #update-btn, #units {
        display: none;
    }

    #nav-left {
        display: none;
    }

    #report-container {
        visibility: visible;
    }

    .well .span12{
        width: 100%;
        visibility: visible;
    }

    .navbar {
        display: none;
    }

    .sidebar-nav {
        display: none;
    }
}

解决方案

Firstly Bootstrap.css does come with pre-defined print styles such as:

/** 
 *  Use these for toggling content for print.
**/
.visible-print {
    display: block !important;
}

.hidden-print {
    display: none !important;
}

Secondly you can test with page-break css rule to separate the charts onto different pages for cleaner formatting.

/** 
 *  Page-break-inside seems to
 *  be required for Chrome.
**/
div.somechart { 
   page-break-after: always; 
   page-break-inside: avoid;
}

Third test with formatting with the rows to take up the full width on print screen rather than relying on percentages of the span3/col-*-3's and span4/col-*-4's, because it would seem they are behaving correctly in some way when you take into account:

Finally the last small thing that's helpful to note (Yes, despite the custom @print style!):

<link href="/assets/css/bootstrap.min.css" rel="stylesheet" media="screen" />

to:

<link href="/assets/css/bootstrap.min.css" rel="stylesheet" media="all" />

这篇关于正确打印 Twitter Bootstrap的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
前端开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆