Problem with overlapping divs - CSS
html, body {margin: 0px; padding: 0px;}
#pageContainer{ margin: auto; padding: auto;}
#contentContainer{ margin:150px; width:1100px; height: 100%; overflow: hidden; }
#leftContainer{ width: 80%; min-height: 800px; background: #009900; float:left;}
#left1{ margin:80px 0 0 80px; height: 550px; top:0px; z-index:1; background: #000000;}
#left2{ margin:80px 0 0 80px; height: 500px; top:110px; z-index:2000; background:#99FFFF; }
#rightContainer{ width: 20%; height: inherit; background: black; float:right;}
/ CSS Document */
I require 2 overlapping divs, which look like the one below.
----------------------
| |
| ------------------ |
| ' '|
| ' '|
| ' '|
| ' '|
| ' '|
| ' '|
| ' '|
----------------------
' '
' '
-------------------
<div id="pageContainer">
<div id="contentContainer">开发者_如何学C
<div id="leftContainer"> Am the left container
<div id="left1">
<div id="left2">
</div>
</div>
</div>
<div id="rightContainer">
</div>
</div>
</div>
The problem is am failing to get the overlap. Where am I going wrong?
Edit 1: topx was a typo, corrected it.
You need to use position: relative
(absolute
or fixed
work as well but they will give you different results) to get them to overlap as stated at W3Schools. You need to add them to #left1
and #left2
. It should be left
or top
, there is no topx
.
You can fiddle with it here at jsfiddle.
精彩评论