ste*_*ped 7 html css printing xhtml stylesheet
我有一个基于XHTML的页面,其中包含管理信息.管理员应该能够打印页面,但我希望它隐藏他们的信息.
有没有办法在打印页面时设置打印区域,或者是单击"打印"按钮时打开没有管理员信息的辅助页面的唯一可行解决方案?
谢谢!
nic*_*715 27
试试这个:
<style type="text/css" media="print">
.dontprint
{ display: none; }
</style>
<div class="dontprint">I'm only visible on the screen</div>
Run Code Online (Sandbox Code Playgroud)
小智 9
您可以display: none使用以下内容将该div的CSS设置为:
@media print {
div.do-not-print {display: none;}
}
Run Code Online (Sandbox Code Playgroud)
它会正常显示,但是当你去打印时,它会使用那个CSS类.
将print.css添加到您隐藏所有不想打印的元素的页面
<link rel="stylesheet" href="print.css" type="text/css" media="print" />
Run Code Online (Sandbox Code Playgroud)
media ="print"属性告诉浏览器使用特定的css文件.
在那个文件中你可以拥有
.admindetails{
display:none;
}
Run Code Online (Sandbox Code Playgroud)