仅关于父容器的定位元素?

时间:2013-01-13 08:41:46

标签: html css

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

<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...
}

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

2 个答案:

答案 0 :(得分:3)

检查一下:

  #container {
  position: relative;
  }

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

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

  #div3 {
  margin: 0px auto;
  }

但这是你在30秒后可以找到关于div定位的解决方案......

答案 1 :(得分:1)

只需使用CSS

position:relative;

div1div2div3上设置此内容。