Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用固定大小的正文打印时如何删除HTML右边距?_Html_Css_Printing - Fatal编程技术网

使用固定大小的正文打印时如何删除HTML右边距?

使用固定大小的正文打印时如何删除HTML右边距?,html,css,printing,Html,Css,Printing,使用以下代码将HTML页面(正文)设置为A4大小: <html> <head> <style type="text/css"> @page { margin: 0; } body, html { margin:0; padding:0; } body { height: 842px; width: 595px; } section { clear: both; } </style> </head>

使用以下代码将HTML页面(正文)设置为A4大小:

<html>
<head>
<style type="text/css">
@page {
  margin: 0;
}

body, html { 
  margin:0; 
  padding:0; 
}

body {
  height: 842px;
  width: 595px;
}

section {
    clear: both;
}
</style>
</head>
<body>
  <section >
    <div style="float:left;height:60px">x</div>
    <div style="float:right;height:60px">y</div>
  </section>
  <section>
    test
  </section>
</body>
</html>

@页面{
保证金:0;
}
正文,html{
保证金:0;
填充:0;
}
身体{
高度:842px;
宽度:595px;
}
部分{
明确:两者皆有;
}
x
Y
测试
它将删除除右边外的所有边距


如何在使用应用于正文的A4页面设置进行打印时删除右边距以标注页面尺寸?

您可以为打印机创建css页:

<link rel="stylesheet" type="text/css" href="printing.css" media="print">

请具体说明。您想添加右边距吗?@Allan标题和消息说,如何在打印时删除边距。在示例代码中使用此选项,添加
body{margin:0;}
@media print
,打印时仍会显示右边距。@RedDragon您在问题中共享了全部代码还是仅共享了一个片段?@RedDragon您忘记关闭标签,可能是导致此问题的原因?感谢您的更正,我忘记关闭头部,但不会改变结果。代码已完成,全部在提供的示例中。@RedDragon如果使用100%宽度,可能会占用所有空间。当我使用JSFIDLE时,我看不到任何余量。
@media print { 
 body { 
    margin:0;
 } 
}