Forum Moderators: not2easy
I keep the print CSS in a separate file, defined in the head of the web page with the "media=print" attribute. But recent discussions in this forum about the use of @media made me wonder whether or not I'd be better off using this rule within a single CSS file for both display on a screen and printing.
Thus, for example, I have a class "signpost", used for such things as links to the top of a page. Links to the top of the page are, of course, extremely useful to come across every couple of paragraphs or so when reading a piece of text on a screen, but a useless annoyance on a piece of paper.
Currently, I have an entry in my general CSS file saying:
.signpost { font-size: 85%; text-align:right; }
.signpost { display:none; }
.signpost { font-size: 85%; text-align:right; }
@media print { .signpost { display:none; }}
The point here is that use of @media means that the complete description of each class can be held together, the whole thing all in in the same file, rather than parts of the description in separate files.
Has anyone any experience of this? Does it make maintenance easier, or is there something that I'm missing? Has anyone any horror stories to warn me off?
A subsidiary (but related) question concerns how browsers treat the two ways of doing this. As far as I understand it, the results should be the same. But if there's one thing I've learned from this forum, it's that you can't assume that, because results should be the same, they will be the same. Any opinions/warnings about this?
In practise I'm pretty sure that most browsers actually download the print stylesheet with the rest of the page - but I would hope that they have the sense to leave it till last.
If you go with the @media rule then your styling must be downloaded by the browser, regardless of whether the user intends to print or not.