元素在打印页面上不可见。

huangapple go评论82阅读模式
英文:

div element is not visible on print page

问题

我有一张表格。在表格上方,我创建了一条水平线。当我点击打印按钮时,整个页面都显示出来,除了那些线条。这些线条是通过以下方式生成的:

$attachLinesTo = $('#dataset-wrap')

function createLine(x1, y1, l, colorClass) {
  return $('<div>')
    .appendTo($attachLinesTo)
    .addClass('line ' + colorClass)
    .css({
      position: 'absolute',
    })
    .width(l)
    .offset({
      left: x1,
      top: y1
    });
}

在正常视图(非打印)下,页面显示一切正常。只有在打印页面上,这些线条才会消失。

我想在打印视图中显示这些线条。

以下是CSS:

.line {
  transform-origin: 0 100%;
  height: 1px;
  border: 0;
}

.black {
  background-color: black;
}
英文:

I have a table. Above the table, I create a horizontal line. When I click on the print button, the whole page is showing except the lines. The lines are generated as follows:

$attachLinesTo = $(&#39;#dataset-wrap&#39;)

function createLine(x1, y1, l, colorClass) {
  return $(&#39;&lt;div&gt;&#39;)
    .appendTo($attachLinesTo)
    .addClass(&#39;line &#39; + colorClass)
    .css({
      position: &#39;absolute&#39;,
    })
    .width(l)
    .offset({
      left: x1,
      top: y1
    });
}

In the normal view (without printing) the page is showing everything correct. Only on the print page, the lines are missing.

I want to show the lines in the print view.

Here the css:

.line {
  transform-origin: 0 100%;
  height: 1px;
  border: 0;
}

.black {
  background-color: black;
}

答案1

得分: 1

默认情况下,您的浏览器不会打印背景颜色。

您必须在浏览器中启用背景打印,或者只需使用一个高度为1px的border-top(或border-bottom),那应该可以工作。

.line {
  transform-origin: 0 100%;
}

.black {
  border-top: 1px solid #000;
}
<div class="line black"></div>
英文:

By default, your browser doesn't print background colors.

You have to either enable background printing in your browser, or just use a border-top (or border-bottom) that is 1px and that should work.

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

.line {
  transform-origin: 0 100%;
}

.black {
  border-top:1px solid #000;
}

<!-- language: lang-html -->

&lt;div class=&quot;line black&quot;&gt;&lt;/div&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年6月13日 02:00:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/76459199.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定