无法覆盖IE11打印页边距

3

我正在制作一个打印页面,让我有点困扰。当我打印特定页面时,似乎无法覆盖IE11的默认页面设置。

也许这是不可能的,但根据我搜索和了解到的,应该是可以实现的。

我有这个样式:

<style type="text/css">
@media print {

@page Section1{ 
size:21.0cm 29.7cm;
margin:1cm 1cm 1cm 1cm;
}
<!--@page { margin-left: 1cm; margin-right:1cm; margin-top:1cm; margin-bottom:1cm; }-->
@page :header { content: none ;} 
@page :footer { content: none ;} 
}

div.Section1 {
page:Section1;
}

body, td {
margin: 0px;
color:#000000;
background:#FFFFFF;

}
h1 {
font-size: 16pt;
}
.header {
font-size: 10pt;
font-weight: bold;
}
.header2 {
  font-weight: bold;
  vertical-align: top;
  text-align:center;
}
.total {
  font-weight: bold;
  text-align:center;
}
.total_right {
  font-weight: bold;
  text-align:right;
}

.noborder {
text-align:center;
border:none;    
}
.text {
  text-align:center;
}

.text_right {
  text-align:right;
}
.text_left {
  text-align:left;
}
.onlytopcenter {
border-top-color:#000000;
border-bottom:none;
border-left:none;
border-right:none;
text-align:center
}

td {
border: solid 1px;
border-color:#CCCCCC;
padding:1px;
font-family: Arial;
font-size: 7pt;
}
table {
border-collapse: collapse;
}

</style>

并且将其应用到我的内容中,调用方式如下:
<div class="Section1">
<table>
...
...
</table>
</div>

当我打印页面时,总是得到默认的边距为19.05毫米(我想)。我可以手动更改,但这对于许多用户使用的系统来说是不可行的。我做错了什么?

1个回答

5
你唯一做错的事情就是使用IE浏览器。 我曾经遇到过同样的问题,后来发现在@meida查询内使用@page无法在IE中起作用。将@page从@media查询中移除,并直接放置,这会有所帮助。
@page {
    size: A4 landscape;
    margin: 4mm;
}
@page :header { content: none ;} 
@page :footer { content: none ;} 

现在IE正确地为打印设置了边距。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接