开发者

html div position absolute inherited?

if my first div is 'postion:absolute' will by 2nd div inherited that?

<div class="positionab">test 1 </div>

<div class="secondiv">  test 2 </div>


.postionab{

position: absolute;
left:0px;
}

when test 2 is rendered on screen it is position on the most upper left .. why is it li开发者_如何学Cke that?


position: absolute will never get inherited - not even for child elements.

why is it like that?

Because secondiv is not a child of positionab. They are completely separate entities.

If you want to place secondiv at the top left corner of positionab, make it a child.

<div class="positionab">
 test 1 

 <div class="secondiv">  test 2 </div>

 </div>


No, the second div doesn't inherit the position attribute.

The reason that the second element is at the top left corner, is that there is no other element in the flow above it. By applying position:absolute to the first element, you take it out of the flow.

An absolutely positioned element doesn't affect the position of any other elements than it's children. An absolutely positioned element is sometimes referred to as a layer, which describes it's way of existing in the page without affecting the regular flow of elements.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜