【问题标题】:How to print web page as it is shown in browser如何打印浏览器中显示的网页
【发布时间】:2016-07-14 17:15:41
【问题描述】:

购物车是使用 BootStrap 3 创建的。

它包含类似 html5 的标记

<span class="login-or-register">
        <a class="color-red" href="/store/Account/LogOn">Enter</a>
        or <a href="/store/Account/Register">Register yourself</a>
    </span>

在浏览器窗口中正常显示。 在 Chrome 打印预览中也显示 urls 和打印输出是丑陋的。 没有指定媒体,因此打印中的输出必须与屏幕中的相同。

如何让用户打印屏幕上显示的购物车页面?

【问题讨论】:

    标签: css html twitter-bootstrap printing


    【解决方案1】:

    Bootstrap 增加了很多打印样式:

    @media print {
        *,:after,:before {
            color:#000!important;
            text-shadow:none!important;
            background:0 0!important;
            -webkit-box-shadow:none!important;
            box-shadow:none!important
        }
        a,a:visited {
            text-decoration:underline
        }
        a[href]:after {
            content:" (" attr(href) ")"
        }
        abbr[title]:after {
            content:" (" attr(title) ")"
        }
        a[href^="javascript:"]:after,a[href^="#"]:after {
            content:""
        }
        blockquote,pre {
            border:1px solid #999;
            page-break-inside:avoid
        }
        thead {
            display:table-header-group
        }
        img,tr {
            page-break-inside:avoid
        }
        img {
            max-width:100%!important
        }
        h2,h3,p {
            orphans:3;
            widows:3
        }
        h2,h3 {
            page-break-after:avoid
        }
        select {
            background:#fff!important
        }
        .navbar {
            display:none
        }
        .btn>.caret,.dropup>.btn>.caret {
            border-top-color:#000!important
        }
        .label {
            border:1px solid #000
        }
        .table {
            border-collapse:collapse!important
        }
        .table td,.table th {
            background-color:#fff!important
        }
        .table-bordered td,.table-bordered th {
            border:1px solid #ddd!important
        }
    }
    

    删除或覆盖它们以获得所需的结果。例如删除打印视图中的网址添加

    @media print{
      a[href]:after {
        content: none !important;
      }
    } 
    

    到您的样式表。

    【讨论】:

    • 我看起来最重要的问题是从打印输出中删除 url。在不更改引导源代码的情况下覆盖这些样式的最简单方法是什么?
    • 很好的答案。谢谢。
    猜你喜欢
    • 2023-03-12
    • 1970-01-01
    • 2010-11-22
    • 2016-02-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多