Forum Moderators: not2easy

Message Too Old, No Replies

Fixed Background Image

         

purus

5:16 am on May 2, 2006 (gmt 0)

10+ Year Member



I'm trying to set up a gradient background fixed at the bottom of my page. I've set it up so that the body has a repeated bg image that blends in with the top of the gradient image, and then there is a div at 100% height with the gradient image position at the bottom of it. At first I tried positioning this div at absolute and it worked great until the content of the page extended beyond the browser window causing a vertical scrollbar to appear. When you scroll it paints the body's bg image on top of the gradient as if the gradient is scrolling along with the window, except that the gradient actually stays at the bottom, it just slowly disappears.

So then I tried changing the div to a relative position. This fixes the above problem, except that when the content on the page does not extend below the available window size, the remaining space in the window gets painted over with the body bg just like when you scroll with absolute positioning.

Is there any way to have this work when the content doesn't extend beyond the available window size, and when it does?

Here is an example of both:

[pearlhorses.com...]
[pearlhorses.com...]

You will need to resize your window when you are viewing the absolute version so that your browser is smaller than the content of the page. Then try scrolling down and you will see the problem.

The design works for all screen resolutions and text sizes with the relative version as long as the content is longer than the browser window, and with the absolute version as long as the content is shorter than the browser window. Is it not possible to have it work regardless?

Moby_Dim

9:39 am on May 2, 2006 (gmt 0)

10+ Year Member



Welcome to WebmasterWorld, purus. The effect you want is possible imho, but by means of adding some javascripting. No "pure css" solution.

Do not post own urls here, please (see TOS).

purus

1:12 am on May 3, 2006 (gmt 0)

10+ Year Member



Sorry about the links. Is there any way I can edit my original message to remove them?

How would I go about addressing this issue with javascript? Is there a way to constantly check the window size against the amount of content in the web page? Because it is a dynamic site, the amount of window space needed will be different for every page and will constantly be changing. Is it possible to monitor those details with javascript and update the CSS as necessary?

Moby_Dim

6:45 am on May 3, 2006 (gmt 0)

10+ Year Member



>>
Is it possible to monitor those details with javascript and update the CSS as necessary?
>>

I think it's possible. I have nothing to do at the moment, and i'll try to research this issue now.

Moby_Dim

2:18 pm on May 3, 2006 (gmt 0)

10+ Year Member



Well, here's a function :

function hmax() {
var elemheight = document.getElementById("bgfooter").scrollHeight;
var winheight;
if(window.opera) {
winheight = document.body.clientHeight;
}
else if(document.all) {
winheight = document.documentElement.clientHeight;
}
else if(document.getElementById) {
winheight = window.innerHeight;
}

if(elemheight <= winheight) {
document.getElementById("bgfooter").style.height = winheight + 'px'
}
return
}

Put it in the <head> section or external js file.

Put this javascript right before </body> tag :
<script type="text/javascript">
<!--
hmax()
// -->
</script>

and you may add onresize event handler with this function to <body> tag too (but in this case the page woun't be valid :( )

css changes :

body
{
background: #000033 url(bg100000.jpg) repeat;
margin: 0;
padding : 0;
}

#bgfooter
{
width: 100%;
background: transparent url(bg-foote.jpg) bottom left repeat-x;
text-align : center;
}

#edge
{
background: transparent url(edge0000.png) top left repeat-y;
width: 722px;
margin: 0 auto;
padding: 0px;
border: 0px;

}

= all height=100% removed and "position" too. "bg-footer" is "bgfooter" now (I do not like '-' in names :)

Try this and drop me a line how it works on your side. The function could be more simple, but 'strict' mode is not good to do some things in ie :(

purus

3:23 pm on May 3, 2006 (gmt 0)

10+ Year Member



Wow, thanks Moby_Dim, that works nicely. I had created a temporary fix with an extremely tall version of the bg image so that I could just use it as the background of the body tag, but that created gratuitous extra file size. This looks like a good alternative.

Thanks for your help.

Moby_Dim

3:47 pm on May 3, 2006 (gmt 0)

10+ Year Member



:)

May I ask you in which browsers and platforms you tested this?