Link to home
Start Free TrialLog in
Avatar of catonthecouchproductions
catonthecouchproductionsFlag for United States of America

asked on

Stacking DIV's on top of each other - most fluid way

I am wondering what is the best method to stacking DIV's on top of each other. I have read some info on some forums about it, but nothing really helped. My HTML looks like:

<img src="images/card.png" alt="my name is ryan coughlin and im a web and graphic designer, this is what I do. im good at php, css, xhtml, javascript. and yes, im for hire" title="my name is ryan coughlin and im a web and graphic designer, this is what I do. im good at php, css, xhtml, javascript. and yes, im for hire" width="779" height="507" border="0" class="top_layer" />
            
            <div class="bottom_layer">
                  <p>Here is my content.</p>
            </div>

i have my page being centered using margin:0 auto; and am not sure on how I can get it right behind the other one.

Thoughts?

Thank you in advance,

Ryan
img.top_layer{
	z-index:1;
}
div.bottom_layer{
	z-index:0;
	background-image:url(images/card-info.png);
	background-repeat:no-repeat;
	height:465px;
	width:709px;	
}

Open in new window

Avatar of David S.
David S.
Flag of United States of America image

z-index only applies to positioned elements.  One of them needs to be absolutely positioned and the other need to be also or have position:relative.

P.S. Are you sure that you're using the alt attribute appropriately? Does it really say that in the image?
Avatar of catonthecouchproductions

ASKER

So in the long run, it does need absolute? Yeah, my image does say that, haha.. thank you! :)

What should I do because wont it appear different on different browsers because of resolution?
While the ways to center non-absolutely positioned elements are better, there is a way to center an absolutely positioned element. For more information see: http://www.dynamicsitesolutions.com/css/center-element/
I took a look at the earlier, then came back read it again and worked it in to my code, but my image doesn't seem like it is in the center, the front image that is. My css for it is:

div.top_layer{
      position:absolute;
      width:779px;
        margin-left: auto;
       margin-right: auto;
       text-align: left;
      z-index:1;
}

And HTML:

      <div class="top_layer">
                  <img src="images/card.png" alt="my name is ryan coughlin and im a web and graphic designer, this is what I do. im good at php, css, xhtml, javascript. and yes, im for hire" title="my name is ryan coughlin and im a web and graphic designer, this is what I do. im good at php, css, xhtml, javascript. and yes, im for hire" width="779" height="507" border="0" />
            </div>
            
            <div class="bottom_layer">
                  <p>This is the kind of stuff I like to do.</p>
            </div>

You can go to ryancoughlin.com to check it out for a live example, also I am in FF 3.0/Mac Leopard

Thank you for your help.

Ryan
ASKER CERTIFIED SOLUTION
Avatar of David S.
David S.
Flag of United States of America image

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
Nice! So this "should" center it 50% absolutely?

Thanks again!

Ryan
You're welcome.

Yes, that's how to center absolutely positioned elements.