So…are you in favour of simply one CSS stylesheet or are there occasions when you would use @import?
I am usually in favour of a single stylesheet (as far as things like resets, layout and typography… I don’t separate those things out in my stylesheets anyway… instead, I follow the HTML source order and write “down”. This means finding all the styles for any one particular element just means looking for that element in the styles… using / or ctrl-f).
The one time I used @import, it was because I had a small stylesheet used by many pages on the same domain, while the rest of the css between them was different. Still, it probably would have been smarter to just re-copy the shared styles into the separate/different stylesheets, but I was relying on caching. Users would cache both the smaller sheet and the main sheet, so when they got to a page with totally different styles, there was only an additional call for the new stylesheet. But a call is a call, and sometimes that matters more than a slight increase in actual filesize by repeating styles.
What Alex says here though will indeed only count as a SINGLE request… while each @import is a whole new file and a whole new request, @media is not. So there is an advantage bandwidth-wise to use this technique (instead of multiple <link> tags in the header).
And here, he means that what’s supposed to happen is, user agents who do not understand the bolded part
@screen and (max-width: 300px) {
will (should) ignore the entire styleset inside.
This includes IE (6-8). You can have IE send its own request for a file with just the desktop styles and “screen” only.
I think I’ll skip the handheld then and just leave things fluid until they reach say iPhone screen dimensions and are caught in my first CSS rule…does that make any sense or am I lost in the woods somewhere?
I said I think handheld is useless… but I mean that as “by itself”. If I have a stylesheet that’s intended for mobiles I’ll add “handheld” to the list of media (for those phones/devices who DO read that) and not have it listed in styles I have for desktops. If you have a wide array of devices to test on, you could see who listens to “handheld” and who uses it exclusively, who adds it to “screen” and who ignores it entirely.
Yet I was reading on a Nokia site that many of their smaller devices will default to their own style unless you specify a CSS rule of ‘handheld’ thus needing a CSS rule from the very beginning!
I read something similar, which is why I did start adding it to my media list in my “basic” styles, which are, as you were thinking of doing, very fluid and mostly state things like colours and typography (also used on the desktop versions but they’re inheriting from the small basic sheet). Normally I would not separate those kinds of styles, but here I’m doing it for different @media.
The smart phones like iPhone kinda have large screens… older phones may have but 100px in (portrait) width. Not sure how far you want to go in support there.
iPhone4 considers itself to have a resolution of like 960px or so, so if you can get ahold of one of those you may want to see which styles that one shows (make it obvious: set different ugly background colours to the body in each media query styleset).
You might want to bookmark ppk’s Mobile pages: he’s got a crapload of them for testing from Vodaphone (while at dinner, he just pulled out like 6 mobiles from his various pockets and put them on the table!).
I should add this to my sig.