重叠div的问题 - CSS

时间:2010-06-03 15:14:58

标签: css overlap

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

我需要2个重叠的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 个答案:

答案 0 :(得分:5)

您需要使用position: relativeabsolutefixed工作,但他们会给您不同的结果)以使它们重叠为stated at W3Schools。您需要将它们添加到#left1#left2。它应该是lefttop,没有topx

You can fiddle with it here at jsfiddle.

相关问题