Previous Message
Next Message

Re: [css-d] CSS for Mac and PC

Sent by Andrew Clover on 31 January 2002 18:06

Kimberly Cox [EMAIL-REMOVED]> wrote:

> I see websites all the time using javascript to load css scripts based on
> their computer and resolution. How is this achievable?

The computer type can be detected by sniffing the window.navigator.platform
property. The resolution of the screen can be sniffed from screen.width and
screen.height in most browsers. Much more useful than the screen resolution
is the actual size of the window, which can be read using window.innerWidth
and innerHeight on many browsers but document.body.offsetWidth/offsetHeight
on Internet Explorer. (In IE6's standards mode you will probably need to
use 'documentElement' instead of 'body' to read the offsetHeight. Either of
these objects can be used for offsetWidth in IE5 and up.)

Once you've decided what stylesheet to link to based possibly on this
information you can output a link. Usually this is done by calling
document.write('<link rel="stylesheet" href="...">') in a <script>
embedded in the <head> element.

But this is normally really last-resort stuff. It's easy to use CSS that
some browsers don't understand in order to hide troublesome styles from
browser that would go wrong if they saw them, and this is normally very
much preferable to client-side browser sniffing. Similarly a flexible
layout is usually a better solution than fixed-size layout customised
for particular browser window sizes. But there are still occasional uses
for it.

> Where can I find more information about writing CSS for MAC if I'm using
> a PC?  Thanks much!

There's very little difference, unless you count minority Mac-only browsers:
OmniWeb and iCab have so many quirks in their current half-arsed CSS support
you're unlikely to get far trying to accomodate them unless you have a Mac
to test them on. Codebitch has some good info if you're interested in these

Apart from that, Opera and Mozilla on the Mac are pretty much the same as
their Windows counterparts. IE/Mac is different in many ways to IE/Win, but
for simple CSS you won't notice the difference - if it works in IE6's
Standards Mode and Mozilla, it's very likely to work in IE5/Mac.

Andrew Clover
Previous Message
Next Message

Message thread: