简体   繁体   中英

How to show print media css on screen?

I have a different CSS that's applied when someone is printing (below is an example of how I'm doing it). But I'm wondering, I'd like to make a custom "Preview Print" (instead of the regular one in the browser) but I'm wondering if it's possible to somehow get it so that the print media css will be applied, because I'd like to show a preview on the screen of what they'll be printing on paper. Any ideas?

<html>
<body>

<style type="text/css">
body 
{
   font-size: 62.5%;
   background-color:black;
}
h1 
{
   color: red;
}
@media print 
{
body{
background-color:yellow;
}

  h1 {
  color: black;
   }
}
</style>

<h1>This is just a test</h1>

</body>
</html>

The easiest way would be to create a print.css style sheet that's normally included with print media specified.

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

Then on your print preview screen, you could use the same print.css with screen media set:

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

我经常打开一个新窗口,用我自己的通用html / body包装器编写,使用打印样式表作为主样式表,使用JavaScript将主体从开启器复制到窗口。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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