我有一个基于此模板制作的index.html:http://startbootstrap.com/template-overviews/sb-admin-2/并进行了一些细微的更改(在我的情况下,我使用了navbar-fixed-top而我更改了.sidebar位置以修复sb-admin- 2.css)
此索引是静态的,仅通过点击事件更改部分内容,例如
(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中打印时,会有一个巨大的左边距。我尝试使用bootstrap打印响应类和在css中修改media @print进行一些更改,但几乎就像firefox根本无法识别media @print中的更改一样。我还尝试了print_printer重置(在about:config中)并在本节中更改了一些打印参数,但是一旦你更换打印机,问题就出现了。 此外,我希望有一个更好的方法,或者我只是在我的代码中做错了,因为很难要求用户做所有这些“解决方法”。
(抱歉任何错误/错误的解释,这是我第一次在这里问一些事情)
答案 0 :(得分:0)
听起来你可能尝试过类似的东西,但以下内容对我有用。顺便说一句,我正在使用bootstrap。
确保您要打印的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;
}
}
}
给这一点。
答案 1 :(得分:0)
遇到了同样的问题(在Firefox中打印出来,有一个巨大的左边距。);之前的答案帮了很多忙。但是,我必须将样式设置为容器类以使一切正常(Bootstrap)。因此,识别正确的div并设置浏览器特定的样式应该可以正常工作。
@@supports (-moz-appearance:meterbar) {
.container {
margin: 0;
font-size: 0.90em;
width: 100%;
}
}