0

我对元素定位的痛苦仍在继续:

<div id="container">
<div id="div1"></div>
<div id="div2"></div>
<div id="div3"></div>
</div>

#div1 {
right:0; // what I want - it's right border should be 0px from the parent's right border, regardless of any other div inside.
}

#div2 {
bottom:0; // it's bottom border should be 0px from the parent's bottom border, regardless of any other div inside.
}

#div3 {
margin-left:auto;
margin-right:auto;
// should be on the parent's center, regardless...
}

所以,我希望父母成为参考,而不是邻居。

4

2 回答 2

3

检查这个:

  #container {
  position: relative;
  }

  #div1 {
  position: absolute;
  right: 0px;
  }

  #div2 {
  position: absolute;
  bottom: 0px;
  }

  #div3 {
  margin: 0px auto;
  }

但这是您在阅读有关 div 定位的 30 秒后可以找到的解决方案...

于 2013-01-13T08:55:12.050 回答
1

只需使用 CSS

position:relative;

将此设置为div1, div2, div3

于 2013-01-13T08:58:56.817 回答