Link to home
Start Free TrialLog in
Avatar of tonelm54
tonelm54

asked on

Left to right fade background

I have a client who wants there web page to have a fade on it, starting from white on the left side, to a grey on the right side. I dont want it to be animated, I dont want to use an image, and it needs to resize with the web page.

Ive searched google and cant even get a close answer to help me.

Any ideas?

Tony Cross
Avatar of TName
TName

Why don't you want an image? A very very narrow long image, vertically repeated as the body's background?
As far as i am aware, there is no way to do this. The only thing that evens seems remotely possible would be to have a series of <DIV>s z-ordered behind the main body of the page, each with aa slightly altered background color.

This would not be smooth (unless you had hundreds of DIVs = a couple of hunrder extra kilobytes of HTML per page) so I wouldn't reccomend it.

The best option _would_ be to use an image as far as I know. Can i ask why you're avoiding that option? The image size can be tiny so shouldn't impact much.

You could have a small script to generate the file based on the browser window width. so it's always white on the R.H.S. Please note: I don't think this is an "elegant" solution, but a possible work-around. Especially as you'd probably have to start with a standard-width image and switch to your custom-width one with javascript once you know the browser's viewing area.

Sorry I couldn't offer anything more helpful. Maybe one of the other experts can tell you more...
Avatar of gamebits
Like TName and basiclife I would recommend the use of a background image, you can create a gradient here

http://www.grsites.com/exec/public/texturegradient.cgi?action=select

Gamebits
I agree an image with a 1px height is the best way to go as it will work with all browsers.  The only other route is to use some CSS that will only be correctly rendered in Internet Explorer.  Users with firefox, opera, netscape, safari, etc will only see a white background.  While I can't in good mind recommend this as the "best" solution, here is how to do it:

<style type="text/css">
<!--
body {
    margin:0px;
      padding:10px;
      height:100%;
    filter:progid:DXImageTransform.Microsoft.Gradient(endColorstr='#99CCFF', startColorstr='#ffffff', gradientType='1');
}
-->
</style>
Sorry, that fades to blue.  Just edit 99CCFF to whatever shade of grey you want.  "bbbbbb" for example.
Another idea  a combination of methods. As js_vaughan said, go the CSS and image route however...

http://www.htmlite.com/faq022.php

demonstrates how to STRETCH not tile the image

This means you'll always have it the right width. If you make the original image 1280 pixels wide, it'll even degrade pretty nicely in browsers that don't use CSS (not many now). Final output looks something like this:

<html>
<head>
<title>How to stretch a background image.</title>
<style type="text/css">
body {margin:0px;}
#bg_image {
width: 100%;
height: 100%;
left: 0px;
top: 0px;
position: absolute;
z-index: 0;
}
#contents {
z-index: 1;
position: absolute;
}
</style>
</head>

<body>

<!-- this creates the background image -->
<div id="bg_image">
<img src="images/scenery.jpg" style="width: 100%; height: 100%;">
</div>

<!-- this puts the contents of the page ontop of the background image -->
<div id="contents">
This is a test.
</div>

</body>

</html>

Another slightly different solution is here: http://Q_20526046.html
ASKER CERTIFIED SOLUTION
Avatar of DreamMaster
DreamMaster

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tonelm54

ASKER

After spending several hours thinking of a solution, I have to agree with DreamMaster, that this would be the best and simplist idea, Thanks for everyones help though!

Tony
I just have to point out that every single person here has suggested using an image and everyone did it before Dreammaster. Is there any particular reason you picked his answer instead of a split?
Maybe because I added the little part about using the same color as the end of your image...so you will never see a part where your background stops...other than that I agree, I said it all after you guys..

Regards,
Max.
True. Please don't think that was a dig at you - it wasn't! I just wondered why he picked one over the rest