|
|
#1 (permalink) |
|
Bow before Surpass!
Super #1
Joined in Sep 2004
1,544 posts
Gave thanks: 91
Thanked 49 times
|
CSS Background question
Can't seem to remember exactly, and tried a bit of a search, but no luck yet.
I'm trying to use CSS (in body {}) to display the background image stretched 100% in size and glued to the bottom, with no image repeat. Anyone got the solution? Thanks.
__________________
Wii Hotspot - Upcoming project! -http://www.wiihotspot.com
Make a cPanel Login Form | Why is my Account Suspended? |
|
|
|
|
|
#2 (permalink) |
|
after g, before i
Resident.
Joined in Jul 2004
Lives in N,BC,CA
8,055 posts
Gave thanks: 48
Thanked 129 times
|
Actually, there is no way to scale an image specified with background-image in the current spec. You'll see background-size in CSS3.
The current suggested methods are to use conditionals (read: media queries which aren't well supported) or to use an img element absolute/fixed positioned, behind everything else (z-index). |
|
|
|
| This user thanks H for this great post! | GamingHybrid (August 31st, 2007) |
|
|
#3 (permalink) |
|
Bow before Surpass!
Super #1
Joined in Sep 2004
1,544 posts
Gave thanks: 91
Thanked 49 times
|
true, I think I found another way, but it might now work. I'm trying it atm.
__________________
Wii Hotspot - Upcoming project! -http://www.wiihotspot.com
Make a cPanel Login Form | Why is my Account Suspended? |
|
|
|
|
|
#4 (permalink) |
|
Bow before Surpass!
Super #1
Joined in Sep 2004
1,544 posts
Gave thanks: 91
Thanked 49 times
|
Apparently it won't I guess I'll just wait for CSS3 then :P The site itself is interactively heavy, so too much patching would be more of a issue than solution.
No wonder couldn't remember, since it can't be done. Thanks H.
__________________
Wii Hotspot - Upcoming project! -http://www.wiihotspot.com
Make a cPanel Login Form | Why is my Account Suspended? |
|
|
|
|
|
#5 (permalink) |
|
Surpass Fan
Excelling Contributor
Joined in Nov 2005
Lives in Colorado
Hosted on DEDI
934 posts
Gave thanks: 2
Thanked 94 times
|
Make your initial page and get your viewable window size using:
<script language="JavaScript"> var width = screen.width; window.location = 'index.php?width=' + width; </script> Immediatly redirecting to a PHP page with: <?PHP $width = $_GET['width']; // resize your master image to the width with GD if needed if (!exists 'master'.$width.'.jpg') { // resize, save, and keep that image } ?> <style> body { background: url(master<?=$width?>.jpg; etc; } </style>
__________________
Where would you be if you were at the highest court in the land (US)? |
|
|
|
| This user thanks cowboy for this great post! | GamingHybrid (August 31st, 2007) |
|
|
#6 (permalink) | |
|
Bow before Surpass!
Super #1
Joined in Sep 2004
1,544 posts
Gave thanks: 91
Thanked 49 times
|
Quote:
Thank you though ![]()
__________________
Wii Hotspot - Upcoming project! -http://www.wiihotspot.com
Make a cPanel Login Form | Why is my Account Suspended? |
|
|
|
|
|
|
#7 (permalink) |
|
after g, before i
Resident.
Joined in Jul 2004
Lives in N,BC,CA
8,055 posts
Gave thanks: 48
Thanked 129 times
|
Hmm. I don't like the proxy to PHP so much. You'd be just as well off to use JavaScript to choose a background image (obviously start off with a default, in the event they don't have JavaScript enabled).
|
|
|
|
|
|
#8 (permalink) |
|
Senior Member
Super #1
Joined in Nov 2003
Lives in New Hampshire
1,220 posts
Gave thanks: 3
Thanked 22 times
|
Execpt the PHP example is platform independent. And javascript is dumb. When you can avoid javascript, do.
Last edited by FredFredrickson; September 6th, 2007 at 2:28 PM. Reason: I can't think good. |
|
|
|
|
|
#9 (permalink) |
|
after g, before i
Resident.
Joined in Jul 2004
Lives in N,BC,CA
8,055 posts
Gave thanks: 48
Thanked 129 times
|
You're putting load on your server, slowing the request for the image AND depending on JavaScript in the first place (how do you think you're getting the height of the window?).
JavaScript is not dumb and far from it. If done properly, people that don't have JavaScript enabled shouldn't really notice. Doing it properly in this case would be creating a background image that will work for your average visitor (either by meeting the lowest significant resolution or the most common). That will be specified in your CSS file that is loaded by everyone. Then using JavaScript, probably triggered onload, you'll use DOM to find the element and replace the background image. |
|
|
|