如何使单个div的内容在打印时填满整个页面

时间:2019-05-07 12:34:36

标签: html css aurelia

我有一个aurela应用程序,需要能够打印出标签。在带有表单的页面上,有一个隐藏的div,其中包含标签的布局。我只想打印隐藏的div,并且希望它被拉伸(带有内容)以使页面在横向尺寸上足够大。目前,它仅占页面的一小部分。

JSFiddle Label

这是我尝试使其工作的CSS。奇怪的是,对@page的更改无济于事。我尝试了不同的页面大小,但没有影响div,它仍然位于一个角落。

    @media print {
  header, footer, .print-hidden {
    visibility: hidden;
  }

  @page {
    size: auto;
    margin: 0mm;
  }

  html, body {
    height: 100%;
    width: 100%;
  }

  .print-show{
    display: block;

    position: absolute;

    width: 100vw;
    height: 100vh;
    top:0;
    bottom:0;
  }
}

这是标签的aurelia模板

<template bindable="firstname, lastname, company, inviter, uniquecode">
<div class="label-container">
<div class="row justify-content-start mx-0 px-1 pt-1">
    <div class="text-center">
        <img class="label-logo" src="image.png">
        <div class="visitor-logo">VISITOR</div>
    </div>
</div>
<div class="flex-row text-center label-name">
    <div>${firstname}</div>
    <div>${lastname}</div>
</div>
<div class="text-center label-company">
    ${company}
</div>
<div class="row justify-content-between mx-0 px-1">
    <div>
        <div class="label-guestof">Guest of</div>
        <div class="label-inviter">${inviter}</div>
    </div>
    <span>${uniquecode}</span>
</div>
</div>

这是标签的自定义CSS类:

    .label-container{
  width: 350px;
  height: 188px;
}

.visitor-logo{
  font-weight: normal;
  font-size: 15px;
  color: #505659;
}

.label-name{
  font-weight: 600;
  font-size: 28px;
  color: #2B3033;
}

.label-company{
  font-weight: normal;
  font-size: 12px;
  color: #737B80;
}

.label-guestof{
  font-weight: normal;
  font-size: 10px;
  color: #737B80;
}

.label-inviter{
  font-weight: 600;
  font-size: 12px;
  color: #505659;
}

.label-logo{
  height: 28px;
  width: 60px;
}

1 个答案:

答案 0 :(得分:0)

我对它进行了一些重新样式设置,并添加了背景色以进行更好的检查。我希望这是您要寻找的。如果不是这样的话,这样做很有趣:P。

<!--index.html-->
<div class="label-container">
  <div class="label-container__header mx-0 px-1 pt-1">
    <div class="text-center">
      <img class="label-logo" src="image.png">
      <div class="visitor-logo">VISITOR</div>
    </div>
  </div>
  <div class="label-container__names label-name">
    <div>${firstname}</div>
    <div>${lastname}</div>
  </div>
  <div class="label-container__company label-company">
    ${company}
  </div>
  <div class="label-container__footer justify-content-between mx-0 px-1">
    <div>
      <div class="label-guestof">Guest of</div>
      <div class="label-inviter">${inviter}</div>
    </div>
    <span>${uniquecode}</span>
  </div>
</div>

// style.css
html, body {
  height: 100%;
  width: 100%;
}

.label-container {
  width: auto;
  height: 100%;
  background-color: #aaa;

  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.label-container__header {
  display: flex;
  justify-content: flex-start;
  align-items: flex-start;
}

.label-container__names {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.label-container__company {
  display: flex;
  justify-content: center;
}

.label-container__footer {
  display: flex;
  justify-content: flex-end;
}

.visitor-logo{
  font-weight: normal;
  font-size: 15px;
  color: #505659;
}

.label-name{
  font-weight: 600;
  font-size: 28px;
  color: #2B3033;
}

.label-company{
  font-weight: normal;
  font-size: 12px;
  color: #737B80;
}

.label-guestof{
  font-weight: normal;
  font-size: 10px;
  color: #737B80;
}

.label-inviter{
  font-weight: 600;
  font-size: 12px;
  color: #505659;
}

.label-logo{
  height: 28px;
  width: 60px;
}