打印网页时如何隐藏元素? [英] How do I hide an element when printing a web page?
问题描述
我的网页上有打印网页的链接.但是,该链接在打印输出中也可见.
I have a link on my webpage to print the webpage. However, the link is also visible in the printout itself.
是否有 javascript 或 HTML 代码可以在我单击打印链接时隐藏链接按钮?
Is there javascript or HTML code which would hide the link button when I click the print link?
示例:
"Good Evening"
Print (click Here To Print)
我想在打印文本晚安"时隐藏这个打印"标签.打印"标签不应显示在打印输出本身上.
I want to hide this "Print" label when it prints the text "Good Evening". The "Print" label should not show on the printout itself.
推荐答案
在您的样式表中添加:
@media print
{
.no-print, .no-print *
{
display: none !important;
}
}
然后在您不想出现在打印版本中的 HTML 中添加 class='no-print'
(或将 no-print 类添加到现有的类语句中),例如作为您的按钮.
Then add class='no-print'
(or add the no-print class to an existing class statement) in your HTML that you don't want to appear in the printed version, such as your button.
这篇关于打印网页时如何隐藏元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!