简体   繁体   English

使用@media in rails项目进行打印的样式表

[英]Style sheets for printing using the @media in rails project

I'm creating a rails 3.2.x project in which I would like to create a stylesheet for printing. 我正在创建一个Rails 3.2.x项目,我想在其中创建用于打印的样式表。 I'm using SASS and the asset pipeline and I've added a file called print.css.scss to my require line in the default loaded sass file. 我正在使用SASS和资产管道,并且在默认加载的sass文件中的我的require行中添加了一个名为print.css.scss的文件。

I've got a class contents and I'm setting the diplay to none for a test. 我有一个课程的内容,并且我将diplay设置为none以进行测试。 If I remove the @media print block then it works on the screen but still not in the printer. 如果我删除@media打印块,则它可以在屏幕上运行,但仍不能在打印机中使用。

@media print {
   .contents {
      display: none;
    }
 }

I've tested printing in Chrome & Firefox, it's like the stylesheet is not getting loaded on print, is there anything else I have to configure? 我已经在Chrome和Firefox中测试了打印,这就像样式表没有加载到打印中一样,我还需要配置其他内容吗?

You should create a print manifest file like this and require your print sass file in it like this. 您应该这样创建一个打印清单文件,并在其中需要您的print sass文件。

print.css print.css

/*
 *= require print
 */

Then in your layout: 然后在您的布局中:

<%= stylesheet_link_tag "print", media: 'print' %>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM