views:

269

answers:

3

Hi all,

I have a website with a fixed background and another little image that is to sit in the center of the page which I have positioned successfully, however the trouble comes when I try to put another div in that is supposed to hold the text and content, it sits underneath the image.

You can view my example here: (Please don't worry about the URL! It isn't anything dodgy or disgusting, it's just my muck around domain). http://liquid-shit.com/csstest.php (the page)

(SO is only letting me post one hyper link so here is the link to the css with it unlinked, remove the space between the /'s)

http:/ /liquid-shit.com/csstest.css (the page)

As you can see at the bottom of the page the two little white flowery images are above the text. I have tried changing the order of the divs in the html and the z-indexes etc.

My CSS is a little rusty and this one has me stuck.

Thanks in advance - Ben

+1  A: 

Fixed positioning will always sit above flow (normal) positioning. You need to change #content to use absolute or fixed positioning and then correctly position the element.

Here is the updated CSS:

#content {
    width:200px;
    min-height:100%;
    margin:auto;
    z-index:1;
    position:absolute;
    left:50%;
    margin-left:100px; /* half the width to obtain proper offset */
}
David Pfeffer
Thanks mate! So simple in the end. I thought it might be.
Ben
A: 

After looking at source code of http://liquid-shit.com/csstest.php, you need to put your content and fixed box in 2 seperate divs

<body>
    <div id="content">
        lorem ipsume says put your content here.
    </div>

    <div id="footer">
        &nbsp;
    </div>

</body>

Fix position of your #footer and give it high z-index in order to have contents of #content go behind it.

rockacola
A: 

I got the effect that I think you're looking for with the following CSS. (This also eliminates the need for the pattern div.)

html, body {
background-color:#000f2f;
background-image:url(backgroundgradient.jpg);
background-repeat:repeat-x;
background-attachment:fixed;
background-position:bottom;
height:100%;
}

#content {
background-image:url(pattern.png) ; 
background-attachment: fixed;
background-repeat:no-repeat;
background-position:bottom;
width:200px;
min-height:100%;
margin:auto;
z-index:1;
}

EDIT: Fixed copy/paste error from previous edit.

Dan Breslau
Oh, and you don't need the z-index anymore, either.
Dan Breslau