隐藏除一个div以外的所有元素以进行打印视图 [英] Hide all elements except one div for print view

查看:77
本文介绍了隐藏除一个div以外的所有元素以进行打印视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的打印样式有以下CSS:

I have the following CSS for my print style:

* {
 display:none;
}

#printableArea {
 display:block;
}

我希望这可以隐藏所有元素,并且只显示printableArea,但是所有都被隐藏了.在打印视图中,我得到的只是一个空白页.

I expected this to hide all elements, and only show the printableArea, however everything gets hidden. In print view, all I get is a blank page.

我已将其正确包含在HEAD中,并在此特定样式表上包含media="print".

I have it included properly in the HEAD, with media="print" on this particular stylesheet.

推荐答案

如果未显示元素,则不会显示其任何子元素(无论其显示属性设置为什么).

If an element is not displayed, then none of its children will be displayed (no matter what their display property is set to).

*<html>元素匹配,因此整个文档都被隐藏了.

* matches the <html> element, so the entire document is hidden.

您需要对隐藏的内容更具选择性.

You need to be more selective about what you hide.

这篇关于隐藏除一个div以外的所有元素以进行打印视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆