PDA

View Full Version : adjusting for different resolutions....



brent
07-14-2002, 08:56 PM
I was just wondering if there was a way to detect the screen resolution someone is using and loading a different CSS file depending on the res they have....is that possible?? the way I am designing things i need to do this for it to work. its the only way!!

thanks....

brent

andrewsheldon98
07-15-2002, 02:25 AM
hi brent,

best thing to do is to use a redirect html file to call a specific html file depending on the screen resolution.
insert this code into your index.html file.

but dont forget to change the hyperlinks to your own

<script language="JavaScript1.2">
<!--

if (screen.width==800||screen.height==600) //if 800x600
window.location.replace("http://yourdomain.com/index800.html")

else if (screen.width==640||screen.height==480) //if 640x480
window.location.replace("http://yourdomain.com/index640.html")

else if (screen.width==1024||screen.height==768) //if 1024x768
window.location.replace("http://yourdomain.com/index1024.html")

else //if all else
window.location.replace("http://yourdomain.com/index800.html")

//-->
</script>


now when you have done this, each different html file you specified in the script, place the desired css file required in them.

brent
07-15-2002, 02:36 AM
thanks man, i will try that out!!!

Gordo
07-15-2002, 05:23 AM
Actually, andrewsheldon98's solution will require you to create web pages for every single browser resolution...or at least as many as you want to make. This will, in turn, will cause you to update each page for each resolution when you make a single update. That could quickly become a pain in the arse!

You said you wanted separate CSS files for various resolutions. I believe the following will take care of you. Now, you'll only need multiple CSS files. This particular example only designates between <=800px and >800px. If you need anything further, I'm fairly certain you'll easily be able to adjust the code accordingly.

Change the colored portions as needed:

<head>

<script>
<!--
if (screen.width <= 800 || screen.height <= 600) {
document.write("<link rel='STYLESHEET' type='text/css' href='css-red-800-or-less.css' title='css800pxorless'>");
}
else if (screen.width > 800 || screen.height > 600) {
document.write("<link rel='STYLESHEET' type='text/css' href='css-blue-above-800.css' title='cssforabove800px'>");
}
-->
</script>

</head>

Any questions?

Vladdy
07-15-2002, 05:54 AM
Or better yet, create a fluid layout that will work with any resolution (including WebTV hehe)

zoobie
07-15-2002, 06:09 AM
You can make all the pages you want...but here's an easy way to center page regardless of resolution:

<body>
<table width="100%" height="100%">
<tr><td align="center" valign="middle">

your html code


</td></tr>
</table>
</body>

The height attribute is for older NS browsers. :p

brent
07-15-2002, 06:53 AM
it would be nice to make it all fluid, but i am using some absolute positioning for things and that obviously changes where things are placed when the resolution is changed......i seem to have it worked out now.....except my friend is using IE 5.5 on a mac, and he said the absolute positioning isnt working on there.....thats a whole new problem. argh.