![]() |
![]() |
![]() |
|||||
![]() |
![]() |
![]() |
![]() |
![]() |
|||
| Welcome
to Tech Support Forum home to more then 136,000 problems solved. Issues
have included: Spyware, Malware, Virus Issues, Windows, Microsoft,
Linux, Networking, Security, Hardware, and Gaming Getting your
problem solved is as easy as: 1. Registering for a free account 2. Asking your question 3. Receiving an answer Registered members: * See fewer ads. * And much more..
|
| Want to know how to post a question? click here | Having problems with spyware and pop-ups? First Steps |
|
|||||||
| Web Design & Programming Discussion of web design, and server-side & client-side scripting |
![]() |
|
|
Thread Tools |
|
|
#1 (permalink) |
|
TSF Enthusiast
|
Making a background image fit multiple resolutions
Hi guys,
This has been driving me nuts for as long as I can remember. I would like to know how to make a background image stretch to fit higher resolutions and shrink to fit lower resolutions. Does anyone know how to do this? Or even know of a website that works this way? |
|
|
|
|
|
#2 (permalink) |
|
Moderator
Join Date: Sep 2004
Location: Colorado
Posts: 761
OS: Mac OS 9.1, Mac OS X 10.5.5, WinXP Pro, FreeBSD 6.0, Gentoo Linux
|
You could probably use JavaScript or PHP to check what the resolution of the screen is, then use variables to control what the image is scaled to when they see it.
Here's how to detect screen size with JavaScript. PHP would probably be a better solution. I think you use the $_GET['width'] and $_GET['height'] variables to get the screen size. |
|
|
|
|
|
#3 (permalink) |
|
TSF Enthusiast
|
Any idea how to implement either of these things so that they'll work with my page?
Like for the javascript...could I use those values as variables, and have different resolutions of that picture available on the server depending on what it returns? PHP's an option too...I just don't know enough to make either of these options happen on my own. Thanks a lot |
|
|
|
|
|
#4 (permalink) |
|
Moderator
Join Date: Sep 2004
Location: Colorado
Posts: 761
OS: Mac OS 9.1, Mac OS X 10.5.5, WinXP Pro, FreeBSD 6.0, Gentoo Linux
|
This should work if you are ok with having a different copy of the image for each resolution.
Code:
<html>
<head>
<title>Resolution dependent background</title>
</head>
<body>
<script language="javascript">
if (screen.width >= 800 && screen.width < 1024)
{
document.body.style.background="url('jscript_test.jpg')"
}
if (screen.width >= 800 && screen.width < 1024)
{
document.body.style.background="url('jscript_test2.jpg')"
}
</script>
<p>Just to see if text works
</p>
</body>
</html>
|
|
|
|
![]() |
| Thread Tools | |
|
|