Solved

Overlay one Div over another's padding, using z-index and position relative to parent Div?

Posted on 2008-10-15
3
2,873 Views
Last Modified: 2013-11-19
Hi,

 I'm trying to get two Divs to overlap and the top one to be placed over the bottom ones Padded area. Tried the code below but obviously this aligns the top Div to the browser.

How would I position it relative to the bottom Div? As a side not I also need to keep the current layout for  #Background and #mainCont as is.

Thanks.
<style type="text/css">

<!--

html, body {

	margin: 0 auto;

}
 

#background {

	text-align: center;

	width: 1680px auto;

	height:100%;

	background-color: #FF6600 ;

}

#mainCont {

	text-align:left;

	margin: 0 auto;

	width: 1300px;

}

#test1 {

	padding: 20px;

	background-color:#00FF33;

	width:200px;

	height:60px;

}

#test2 {

	background-color:#3399CC;

	width:40px;

	height:20px;

}
 

.overlap {

position:absolute;

left:20px;

top:0px;

z-index:1;

}

-->

</style>
 
 
 

<div id="background">

  <div id="mainCont">  

    <div id="test1">test1</div>

    <div class="overlap" id="test2">test2</div>

  </div>

</div>

Open in new window

0
Comment
Question by:sany101
3 Comments
 
LVL 42

Accepted Solution

by:
David S. earned 500 total points
Comment Utility
Give #mainCont position:relative

More information: http://www.dynamicsitesolutions.com/css/layout-techniques/#abs_rel_pos
0
 
LVL 1

Expert Comment

by:Rapturer
Comment Utility
Hi Sany,

This one is easy...you have your overlapped div content within another div that is not.

This will get it done for you:

#test2 {
        background-color:#3399CC;
        width:40px;
        height:20px;
        left:120px;
        top:30px;
           
}
0
 

Author Comment

by:sany101
Comment Utility
Thanks Kravimir you don't know how long I spent scratching my head on this one.... Works a dream and thanks for the link info.

Repturer that didn't seem to work for me but thanks for the imput.

If only they where all this simple.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

CSS is a visual language used to classify objects and define rules about how they should be displayed. CSS skills aren’t restricted to developers anymore, there is a big benefit to having a basic understanding of the language, regardless of your occ…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now