当前位置: 首页 > 图文教程 > 网页制作 > CSS样式表 > 打印网页中不打印页面中的某些内容

CSS样式表
推荐一篇利用th,colgroup,col定义表格样式
都是IE惹的祸多浏览器兼容问题
dl,dt,dd制作的CSS垂直菜单
推荐css打造经典鼠标触发显示选项
div+css中Class与ID的区别
CSS Div 最小高度在IE 6 和IE 7中的兼容性问题
让iframe自适应高度(支持xhtml)IE firefox兼容
实用的利用 CSS + <em>标签 来完成一个三角形的制作
CSS控制文本自动换行的问题
把 CDATA 中的内容(有可能是不规范的Html代码)以Html方式展现出来。
仿客齐集首页导航条DIV+CSS+JS [代码实例]
关于margin-left的示例代码
CSS优化2-(常用CSS缩写语法总结)
font和line-height之CSS代码书写顺序不同,导致显示效果不一样
推荐三种简洁的Tab导航(网页选项卡)简析
用纯CSS+DIV写的漂亮Flash幻灯片及SQL标签教程!
解决IE5/IE5.5/IE6/FF的兼容性问题——CSS
CSS2实现的隔行换色
CSS中几种常见的注释
dhtml shtml xhtml的区别解析

CSS样式表 中的 打印网页中不打印页面中的某些内容


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-12   浏览: 148 ::
收藏到网摘: n/a

其实很简单,用一个CSS就可以实现了,这个方法同时支持IE和FF。
HTML内容
XML/HTML Code复制内容到剪贴板
       
  1. <HTML>    
  2.    
  3.   <HEAD>    
  4.    
  5.     <TITLE>Test Print</TITLE>    
  6.    
  7.     <STYLE type="text/css">    
  8.    
  9.         .css1 {    
  10.    
  11.             text-align: center;    
  12.    
  13.             text-align: center;    
  14.    
  15.             height: 250;    
  16.    
  17.             width: 400;    
  18.    
  19.             background-color: blue;    
  20.    
  21.         }    
  22.    
  23.         .css2 {    
  24.    
  25.             text-align: center;    
  26.    
  27.             height: 250;    
  28.    
  29.             width: 400;    
  30.    
  31.             background-color: red;    
  32.    
  33.         }    
  34.    
  35.         @media print {    
  36.    
  37.             .printbtn, .css1 {    
  38.    
  39.                 display: none;    
  40.    
  41.             }    
  42.    
  43.         }    
  44.    
  45.     </STYLE>    
  46.    
  47.   </HEAD>    
  48.    
  49.   <BODY>    
  50.    
  51.     <DIV class="printbtn"><INPUT type="button" value="Print" onclick="window.print()"/> Print button can't print out, But it can display in page.</DIV>    
  52.    
  53.     <DIV class="css1"><BR/><BR/><BR/>Not print out</DIV>    
  54.    
  55.     <DIV class="css2"><BR/><BR/><BR/>Print out</DIV>    
  56.    
  57.   </BODY>    
  58.    
  59. </HTML>  

主要是在于CSS @media print,这个定义了打印时引用的CSS。css1定义了display: none;,所以打印时css1的类型不会被打印。