Heim  >  Artikel  >  Web-Frontend  >  如何为要被打印的内容设置CSS样式属性_html/css_WEB-ITnose

如何为要被打印的内容设置CSS样式属性_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:30:581098Durchsuche

如何为要被打印的内容设置CSS样式属性:
有时候我们要打印的内容也是需要美观度的,并不希望太原汁原味了,所以要对其进行一下样式设置,本章节就简单介绍一下,如何利用CSS设置要被打印内容的样式,方式有多种,下面一一做一下简单介绍。
一.使用link引入外部样式表:

 

<link rel="stylesheet" href="css/style.css" media="screen" />

 

以上代码的CSS样式用于屏幕显示效果,对于打印无效。关键在于media属性值。

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

以上代码的样式代码可以用于打印内容。
二.import方式引入样式表:

 

<style type="text/css">@import url("css/printstylesheet.css") print;</style>

 

以上代码引入的样式可以用于打印样式。
三.屏幕显示和打印在同一个文件中:

 

@media print{h1{color:black;}h2{color: gray;}}div{color:red}

 

原文地址是:http://www.softwhy.com/forum.php?mod=viewthread&tid=11495

更多内容可以参阅:http://www.softwhy.com/divcss/

 

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn