Forum Moderators: not2easy
Is it possible to combine styles for different media types into just one file, limited the number of server head requests?
Something like:
HTML file:
...
<link rel="stylesheet" type="text/css" href="/style.css">
...
CSS file:
<style type="text/css" media="screen">
...
</style>
<style type="text/css" media="print">
...
</style>
<style type="text/css" media="handheld">
...
</style>
Thanks
Separated CSS files are small and don't really impact document load time very much - it's images and applets that are the heavy burdens.
Is it possible to combine styles for different media types into just one file, limited the number of server head requests?
Not as far as I know...
Yeah, I don't think so either...
Yes, it is possible [w3.org].
You simply define the various media types inside one stylesheet:
@media screen {
p { color:#f90; }
}@media print {
p { color:#000; }
}
-b
Though if you need to be compliant with older browsers, there's this:
[westciv.com...]
But otherwise, I learnt something new :)
I need to test a few things and if it all works nicely in all important browsers, ... A last line in your css that basically hides the navigation could be used for "print", that would be a cool way of needing one less stylesheet indeed. And make maintenance of stylesheets much less of a burden.
[normal stylesheet without the @media]
@media print {
navigation { display:none }
}
Thanks so much for the feedback.
I'll definitely have to run some tests, but it looks like one way to combat browser support is to define shared basics (and maybe the screen version) using the default method, and overwrite various aspects using the @media.
That way, worse case scenario, it would look correct on every body's monitors, but other medias such as printing, won't be as great on the older browsers.
Thanks again.
Example
@media print {
#header, #footer, #menu, #etc {
visibility: invisible;
}
}
* {border:0;padding:0}
This forces all css-enabled browsers to use your style sheet and ignore their own 'independant' style rules.
It is a little more work however, as you then have to redefine everything - but, it is worth the effort to take control.
Eric Meyer explains better: [meyerweb.com...]
[normal plain stylesheet no @media]
@media print {
.navigation, .crumbar [,...] { display:none }
}
Seems to work great in all browsers I care for on a test site I'm doing It's a lot easier to edit it as you ware developing a style as well as it's all in the same file. Add a to be hidden tag, add it at the bottom as well ...