首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用printJS覆盖css

用printJS覆盖css
EN

Stack Overflow用户
提问于 2019-07-23 08:37:23
回答 1查看 700关注 0票数 0

我需要默认的引导css留原样时,打印一个固定的标题的表格,但需要覆盖一些与溢出相关的样式,因为表格是垂直滚动的。

基本上,我想让targetStyles:'*‘与我的bootstrap css模板中的内容相匹配,但需要覆盖tbody {overflow:auto}和另一个自定义样式.table-responsive {overflow-x:auto}。如何在保留所有引导css的同时更改打印作业的这两种样式?

我已经尝试使用targetStyles:和style:,并列出了这两种样式。对于这种情况,https://printjs.crabbly.com/#documentation很有帮助,但还不够直观

代码语言:javascript
复制
/* my table is contained in a div with id of #howDoingTable */
printJS({
   printable: 'howDoingTable',
   type: 'html',
   targetStyles: ['*'],
   style: '#howDoingTable tbody {overflow:none;} #howDoingTable.table-responsive {overflow-x:none;}'              
});
/*It's ignoring the style with the two overrides I want to implement via style:*/
EN

回答 1

Stack Overflow用户

发布于 2019-07-24 04:50:14

除非在当前提供的printJS中不能做到这一点,否则我发现解决方法是在调用printJS之前更改需要更改的样式,然后在调用jQuery之后立即重新启用它们:

代码语言:javascript
复制
      //change overflow css to visible to remove scrolling in the ui
      $("#howDoingTable.table-responsive").css("overflow-x","visible");
      $("#howDoingTable tbody").css("overflow","visible");
      printJS({
          printable: 'howDoingTable',
          type: 'html',
          targetStyles: ['*']            
      });
      //change the overflow css properties back to scrolling
      $("#howDoingTable.table-responsive").css("overflow-x","auto");
      $("#howDoingTable tbody").css("overflow","auto");
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57155265

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档