简体   繁体   中英

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. 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.

I've got a class contents and I'm setting the diplay to none for a test. If I remove the @media print block then it works on the screen but still not in the printer.

@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?

You should create a print manifest file like this and require your print sass file in it like this.

print.css

/*
 *= require print
 */

Then in your layout:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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