Forum Moderators: not2easy

Message Too Old, No Replies

Need solution to Positioning Images behind main Container Div.

         

pghtech

2:32 pm on Mar 10, 2008 (gmt 0)

10+ Year Member



Posted: Mon, 2008-03-10 14:21

Greetings all:
I was in need of the best or correct way to position two images based on the location of the container div.

Basically, I have the container div that contains all the sections of my website and is positioned at the top middle of the page, and I would like an image to site "behind" the top right corner of the container but 90% of the image would stick past (to the right) of the container's right border. This would probaly never change as the image is at the top, and the container will not be expanding width wise.

Then I have a "second" image that I would like to sit partially "underneath" the bottom left corner of the container - but it wouldn't only be positioned to the right of the container but also below the container as well. Visually: The bottom right corner of the container would be sitting in ontop in the middle of the image.

The trick though, is that the "height" of the page will change from page to page depending on content as it is an elastic setup as opposed to a fix width/height and if possible would like the left bottom image to adjust based on the containers position - in the case one page is longer than the next, the image will adjust.

What I have come up with is having a page with 3 columns - the center containing the Header, main, and footer, while the left and right outer columns would contain the image respectively and can be positioned using background (vertical/horizontal) positioning. I haven't tried it to know if this would be a possible option - but even if it does work, I don't know if the "left" column where the picture would have to adjust based on the length of the page would, adjust automatically.

Any advice on how to make this happen would be greatly appreciated.

Regards,

Max

MarkFilipak

6:06 pm on Mar 10, 2008 (gmt 0)

10+ Year Member



If I understand (I hope that the following is not too cryptic)...

<div id='container'><div id='bottomLeftImage'></div></div>

Taking some liberties with notation...
Suppose that I call the value of bottomLeftImage width, <#bottomLeftImage{width}>, and the value of its height, <#bottomLeftImage{height}>. Since these values are constants, #bottomLeftImage's position properties can be set to:
#bottomLeftImage{left:-<#bottomLeftImage{width}/2>}
#bottomLeftImage{bottom:-<#bottomLeftImage{height}/2>}
Since left and bottom are negative -- negative values are allowed by the CSS spec -- the image will "stick out" below and to the left of #container's left-bottom corner. If the content in #container changes its height, the "stick out" should track it.

MarkFilipak

8:01 pm on Mar 10, 2008 (gmt 0)

10+ Year Member



Responding to your private email:

OK, an example with real numbers.

Suppose your bottomLeftImage is 200px wide and 500px high. Your style should be


#bottomLeftImage{left:-100px;bottom:-250px}

This will slide bottomLeftImage to the left and down just the right amount (half).

pghtech

8:29 pm on Mar 10, 2008 (gmt 0)

10+ Year Member



Thanks Mark:
I currently have a (1-column, 3 row) CSS layout.

Could I do that with it and have 2 images and position them using your method and have

- #bottomleftimage
and
- #toprightimage

?

Or would i need to do what I mentioned and that is setup an outer left div and an outer right div?

MarkFilipak

10:36 pm on Mar 10, 2008 (gmt 0)

10+ Year Member



You can do what you want with one div-element and two img-elements. To be positioned relative to the div, the two images must be inside (children of) the div. None of these elements need to be absolutely positioned.
<div id='container'>
...YOUR-CONTENT-HERE...
<img id='bottomleftimage' src='...'></img>
<img id='toprightimage' src='...'></img>
</div>

The following positions your images and puts them behind #container.
#container{z-index:2}
#toprightimage{right:...;top:...;z-index:1}
#bottomleftimage{left:...;bottom:...;z-index:1}

The key to making the overlap is that the values for right, top, left, and bottom can be negative.

Just try it. You'll see.

MarkFilipak

7:11 pm on Mar 12, 2008 (gmt 0)

10+ Year Member



> None of these elements need to be absolutely positioned.
Oops! WRONG! (hey I'm human ...well...)

(Responding to personal mail...)

1. Never do this: {z-index:-1}. It's verboten! (Besides that, it doesn't work. :)

2. {top:...}, {right:...}, {bottom:...}, and {left:...} only work for {position:absolute} and {position:relative}.

3. Since you said that you wanted the bottom-left corner of #container to be in the center-middle of #bottomleftimage, and you do have #bottomleftimage{left:-50px;bottom:-50px}, I assume that #bottomleftimage{width:100px;height:100px}. You really aught to have that as explicit CSS.

4. By all means, put #bottomleftimage and #toprightimage inside #container, not outside #container. It will work better and you might no longer need #wrapper at all!

5. If you really do need #wrapper (e.g. #container relies on background-color to occlude the images), try
#wrapper{z-index:0} /* START A NEW INDEXING SCHEME */
#bottomleftimage,#toprightimage{z-index:1} /* PUT THESE ON TOP */
#container{z-index:2} /* PUT THIS ON TOP OF THOSE */
#wrapper,#container{position:absolute} /* THIS IS REQUIRED FOR left, bottom, & z-index TO WORK */