简体   繁体   English

HTML/CSS - 需要在屏幕和打印页面上的不同位置

[英]HTML/CSS - need different positions on screen and on printed page

I have a HTML and CSS file which are linked.我有一个链接的 HTML 和 CSS 文件。

I have 10 images, in the CSS files these are specifically positioned to display one under the other on screen using "position: absolute;"我有 10 张图片,在 CSS 文件中,这些图片专门定位为使用“位置:绝对;”在屏幕上的另一张下方显示一张图片。

I am now trying to print the file, and want to have one image per page.我现在正在尝试打印文件,并希望每页有一个图像。 Is there any possible way of overriding the "absolute" position and printing one image to a page?有没有可能覆盖“绝对”位置并将一个图像打印到页面上的方法?

Should I be using 2 attached CSS files (@media screen & @media print)?我应该使用 2 个附加的 CSS 文件(@media screen & @media print)吗?

Any help appreciated!任何帮助表示赞赏!

First You can take a look at Paged Media query for more fancy stuff: https://www.smashingmagazine.com/2015/01/designing-for-print-with-css/ and https://developer.mozilla.org/pl/docs/Web/CSS/@page首先,您可以查看 Paged Media 查询以获取更多花哨的内容: https : //www.smashingmagazine.com/2015/01/designing-for-print-with-css/https://developer.mozilla.org/ pl/docs/Web/CSS/@page

Second thing is how HTML file is constructed.第二件事是如何构造 HTML 文件。 If by hand, maybe You could split it into separate files.如果手动,也许您可​​以将其拆分为单独的文件。 If You using some code (like Java, Python, Php, Ruby, Js...) to output HTML then You could output 2 versions accordingly, or use bool "flag" to change it as needed.如果您使用一些代码(如 Java、Python、Php、Ruby、Js...)来输出 HTML,那么您可以相应地输出 2 个版本,或者根据需要使用 bool“标志”来更改它。

You can also try to combine Paged Media and @media print.您也可以尝试结合 Paged Media 和 @media 打印。

Multiple @media rules can be in single CSS file, though of course for bigger thing a good practice is to keep things in multiple files and only output as one with tools like SASS or LESS.多个@media 规则可以在单个 CSS 文件中,但当然对于更大的事情,一个好的做法是将内容保存在多个文件中,并且仅使用 SASS 或 LESS 等工具作为一个输出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM