重叠的div问题-CSS

3
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 */

我需要两个重叠的div,看起来像下面这个。

    ----------------------
   |                      |
   |   ------------------ |
   |  '                  '|
   |  '                  '|
   |  '                  '|
   |  '                  '|
   |  '                  '|
   |  '                  '|
   |  '                  '|
    ----------------------
      '                  '
      '                  '
       -------------------


<div id="pageContainer">
  <div id="contentContainer">
    <div id="leftContainer"> Am the left container 
      <div id="left1"> 
          <div id="left2">
          </div>
      </div>
    </div>
    <div id="rightContainer">

    </div>
  </div>
</div>

问题是我无法获得重叠部分。我做错了什么?
编辑1:topx是一个打字错误,已经更正。
1个回答

5
你需要使用position: relativeabsolutefixed也可以,但它们会产生不同的结果)才能使它们重叠,正如W3Schools所述。你需要将它们添加到#left1#left2中。应该是lefttop,没有topx你可以在jsfiddle上进行测试。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接