If my first div is ‘postion:absolute’ will my second div inherit that?
When test 2 is rendered on screen it is positioned on the most upper left. Why is it like that?
.postionab {
position: absolute;
left: 0px;
}
<div class="positionab">test 1 </div>
<div class="secondiv"> test 2 </div>
No, the second
divdoesn’t inherit thepositionattribute.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:absoluteto the first element, you take it out of the flow.An absolutely positioned element doesn’t affect the position of any other elements than its children. An absolutely positioned element is sometimes referred to as a layer, which describes its way of existing in the page without affecting the regular flow of elements.