如何在打印网页时隐藏元素? [英] How do I hide an element when printing a web page?

查看:435
本文介绍了如何在打印网页时隐藏元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的网页上有一个链接,可以打印网页。

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;
    }
}

然后添加 class = no-print'(或将无打印类添加到现有类语句),您不希望显示在打印版本中,例如您的按钮。我得到这个工作与'noPrint'而不是'noprint'(小写)。

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. I got this to work with 'noPrint' instead of 'noprint' (lowercase).

这篇关于如何在打印网页时隐藏元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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