div 设置a4大小_将div拉伸到A4大小

I have the following function which works great.

function printDiv(printpage)

{

var headstr = "

";

var newstr = document.all.item(printpage).innerHTML;

var oldstr = document.body.innerHTML;

document.body.innerHTML = headstr+newstr;

window.print();

document.body.innerHTML = oldstr;

return false;

}

However my div is about half of the paper size. Is there a way to make my div stretch to a full paper size when the function is called?

解决方案

You can set the div size by css to fit it in a A4 size paper

CSS:

body {

margin: 0;

padding: 0;

background-color: #FAFAFA;

font: 12pt "Tahoma";

}

* {

box-sizing: border-box;

-moz-box-sizing: border-box;

}

.page {

width: 21cm;

min-height: 29.7cm;

padding: 2cm;

margin: 1cm auto;

border: 1px #D3D3D3 solid;

border-radius: 5px;

background: white;

box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);

}

.subpage {

padding: 1cm;

border: 5px red solid;

height: 237mm;

outline: 2cm #FFEAEA solid;

}

@page {

size: A4;

margin: 0;

}

@media print {

.page {

margin: 0;

border: initial;

border-radius: initial;

width: initial;

min-height: initial;

box-shadow: initial;

background: initial;

page-break-after: always;

}

}

HTML:

Page 1/2
Page 2/2
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值