5

How do I add a print stylesheet in Drupal 8? Here is what my libraries file looks like in my theme...

global-styling:
  version: 8.0
  css:
    base:
      css/style.css: {}
    theme:
      css/print.css: { media: print }

Does that look correct? If it is correct, should I also include print media queries in the print.css file? Or do I not need those media queries because of the "media: print" annotation in my libraries file?

Since I can't inspect the print-preview source, how do I know what classes to use in my print CSS?

(And is there anything else in Drupal 8 that influences the print styles? I am working on a site I did not build, and it has print styles, but I don't know where they are coming from. I thought maybe they were coming from the base theme, but I removed the base theme from my theme's info file and I continue to see styled output when I print-preview the page. The styled output is bad, and needs to be corrected, but I don't know where it's coming from.)

  • 3
    Since I can't inspect the print-preview source The source is the source of your web page – Clive Jan 21 '19 at 18:59
3

If it is correct, should I also include print media queries in the print.css file?

It's correct, and there's no need for media queries in the CSS file.

(Separately, I'm still trying to determine what else is supplying the print styles in my site, aside from the ones I'm adding intentionally. But I can confirm that the above annotation example works.)

| improve this answer | |
  • Bootstrap was supplying the existing print styles. I didn't realize the sub theme had a sub theme. – arnoldbird Jan 22 '19 at 0:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.