CSDN页面完美格式打印

在CSDN网站直接使用Ctrl + P打印会出现页面显示不全、格式混乱的问题,原因是页面CSS等元素影响了打印效果。解决方法是通过Chrome或Firefox的开发者工具,清除干扰元素。只需复制特定代码到开发者工具的console运行,即可实现页面的整洁打印。
摘要由CSDN通过智能技术生成

如果直接在CSDN页面上Ctrl + P打印,肯定会是这样的预览页面
在这里插入图片描述
页面显示不全,格式不正确,等等。
这是因为页面的CSS等元素干扰了打印。

只要把那些干扰元素删除,再打印就OK了

复制以下代码,打开要打印的页面。

 (function(){

    $("#side").remove();

    $("#comment_title, #comment_list, #comment_bar, #comment_form, .announce, #ad_cen, #ad_bot").remove();

    $(".nav_top_2011, #header, #navigator").remove();

    $(".csdn-side-toolbar,.template-box,.reward-user-box").remove();

    $(".p4course_target, .comment-box, .recommend-box, #csdn-toolbar, #tool-box,#dmp_ad_58").remove();

    $("aside").remove();

    $(".tool-box").remove();

    $("main").css('display','content');

    $("main").css('float','left');

    $("#mainBox").css('width','1048px');

    $("#mainBox").css('margin-left','0px');

    $("#mainBox").css('margin-right','0px');

    //$("[class='main_father clearfix d-flex justify-content-center']").css("width","1048px");

    $(".main_father.clearfix.d-flex.justify-content-center").css("width","1048px");

    window.print();

    $("tool-box").remove();

    })();

打开Chrome或者Firefox的开发者工具的console。(设置->更多工具->开发者工具)
将代码粘贴到console中,回车。
在这里插入图片描述
在这里插入图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值