【问题标题】:Printing Bootstrap page in Firefox在 Firefox 中打印引导页面
【发布时间】:2015-01-03 00:35:20
【问题描述】:

我有一个基于此模板制作的 index.html:http://startbootstrap.com/template-overviews/sb-admin-2/,并做了一些小改动(在我的情况下,我使用了 navbar-fixed-top 并将 .sidebar 位置更改为在 sb-admin-2 中固定。 css)

这个索引是静态的,只通过点击事件改变section内容,例如

(一段 index.html)

<!DOCTYPE html>
<html lang="en">

<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>System User's Guide</title>

    <!-- Bootstrap Core CSS -->
    <link href="css/bootstrap.min.css" rel="stylesheet" media="all">

    <!-- MetisMenu CSS -->
    <link href="css/plugins/metisMenu/metisMenu.min.css" rel="stylesheet">

    <!-- Custom CSS -->
    <link href="css/sb-admin-2.css" rel="stylesheet">

    <!-- Custom Fonts -->
    <link href="font-awesome-4.1.0/css/font-awesome.min.css" rel="stylesheet" type="text/css">

    <script src="js/respond.js"></script>

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
        <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

</head>

<body>

 <div id="wrapper">

        <!-- Navigation -->
        <nav class="navbar navbar-default navbar-fixed-top" role="navigation" style="margin-bottom: 0" id="top">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="index.html">System</a>
            </div>
            <!-- /.navbar-header -->  

            <div class="navbar-default sidebar" role="navigation">
                <div class="sidebar-nav navbar-collapse">
                    <ul class="nav" id="side-menu">
                        <li class="sidebar-search">
                            <div class="input-group custom-search-form">
                                <input type="text" class="form-control" placeholder="Search...">
                                <span class="input-group-btn">
                                <button class="btn btn-default" type="button">
                                    <i class="fa fa-search"></i>
                                </button>
                            </span>
                            </div>
                            <!-- /input-group -->
                        </li>
                        <li class="active"><a href="index.html">Home</a></li>
                        <li><a onclick="openPage('pages/login/loginwelcome.html')" href="#">Login & Welcome</a></li>                       
                    </ul>
                </div>
                <!-- /.sidebar-collapse -->
            </div>
            <!-- /.navbar-static-side -->
        </nav>

        <!-- Page Content -->
        <div id="page-wrapper">
            <div class="row">
                <div class="col-xs-12">
                    <div id="content">
                        <h1 class="page-header">Home</h1>
                        <p>Welcome to our User Guide.</p>
                    </div>    
                </div>
                <!-- /.col-lg-12 -->
            </div>
            <!-- /.row -->
        </div>
        <!-- /#page-wrapper -->

    </div>
    <!-- /#wrapper -->

    <!-- jQuery Version 1.11.0 -->
    <script src="js/jquery-1.11.0.js"></script>

    <!-- Bootstrap Core JavaScript -->
    <script src="js/bootstrap.min.js"></script>

    <!-- Metis Menu Plugin JavaScript -->
    <script src="js/plugins/metisMenu/metisMenu.min.js"></script>

    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
    <script src="js/ie10-viewport-bug-workaround.js"></script>

    <!-- Custom Theme JavaScript -->
    <script src="js/sb-admin-2.js"></script>

    <script>
        function openPage(page) {
            $("#content").load(page);
    }
</script>

</body>

</html>

(loginwelcome.html)

<html>    
    <h1 class="page-header">Login & Welcome</h1>
    <ol class="breadcrumb">
        <li><a href="index.html">Home</a> <span class="glyphicon glyphicon-circle-arrow-right"></span></li>
        <li class="active">Login & Welcome</li>
    </ol>


<div class="panel-group" id="accordion">
  <div class="panel panel-default">
        <div class="panel-heading">
      <h4 class="panel-title">
        <a href="#links" class="accordion-toggle" data-toggle="collapse" data-parent="#accordion">Content<span class="glyphicon glyphicon-chevron-down pull-right"></span></a>
      </h4>
    </div>
    <div id="links" class="panel-collapse collapse in">
      <div class="panel-body">
        <a href="javascript:openPage('pages/login/login.html')">Login</a></br>
        <a href="javascript:openPage('pages/login/welcome.html')">Welcome Screen</a></br>
      </div>
    </div>
  </div>
 </div>

        <p>Test</p>
</html>

所以,问题是:当我尝试在 Chrome 或 IE 中打印 loginwelcome.html 时,它工作得很好(将内容 div 宽度扩展到 100%,隐藏侧边栏等)。但是当我尝试在 Firefox 中打印时,左边距很大。我尝试使用引导打印响应类和修改 css 中的媒体 @print 进行一些更改,但几乎就像 Firefox 根本无法识别媒体 @print 中的更改一样。我还尝试了 print_printer 重置(在 about:config 中)并在本节中更改了一些打印参数,但是一旦您更改了打印机,问题就会再次出现。 另外,我希望有更好的方法来做到这一点,或者我只是在我的代码中做错了,因为很难要求用户执行所有这些“解决方法”。

(抱歉有任何错误/不好的解释,这是我第一次在这里问问题)

【问题讨论】:

    标签: twitter-bootstrap firefox dynamic printing


    【解决方案1】:

    听起来您可能已经尝试过类似的方法,但以下方法对我有用。顺便说一句,我正在使用引导程序。

    确保您要打印的 DOM 元素具有“可打印”类。

    在你的 css 中,确保你有:

    @media print {
      html, body {
        height: 100%;
        overflow-x: hidden;
        overflow-y: hidden;
      }
      .printable {
        position: absolute;
        left: 0;
        top: -13%;
        width: 100%;
       }
      // Firefox-specific print styling:
      @supports (-moz-appearance:meterbar) {
        .printable {
          left     : -50%;
          width    : 200%;
          font-size: 0.85em;
        }   
      }
    }
    

    试一试。

    【讨论】:

      【解决方案2】:

      遇到了同样的问题(在 Firefox 中打印,左边距很大。);以前的答案有很大帮助。但是,我必须将样式设置为容器类以使一切正确(引导程序)。因此,识别正确的 div 并设置浏览器特定的样式应该可以正常工作。

      @@supports (-moz-appearance:meterbar) {
        .container {
          margin: 0;
          font-size: 0.90em;
          width: 100%;
        }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-04-13
        • 1970-01-01
        • 2013-12-13
        • 1970-01-01
        相关资源
        最近更新 更多