Absolute positioning allows you to literally place any page element exactly where you want it. You use the positioning attributes top, left bottom and right to set the location. These values will be relative to the next parent element with relative (or absolute) positioning. If there is no such parent, it will default all the way back up to the element itself meaning it will be placed relatively to the page itself.
Below is the code, where absolute positioned child(p
) will be relative to the next parent element(div
) with absolute positioning, but the div
block width is zero.
<div style= "position:absolute;">
<p style = "position:absolute; top:4px; left:5px;">
text text
</p>
<br/> <br/> <br/> <br/> <br/>
<br/> <br/> <br/> <br/> <br/>
</div>
Below is the code, where absolute positioned child(p
) will be relative to the next parent element(div
) with relative positioning, with the div
block width as non-zero.
<div style= "position:relative;">
<p style = "position:absolute; top: 1px; left: 5px;">
text text
</p>
<br/> <br/> <br/> <br/> <br/>
<br/> <br/> <br/> <br/> <br/>
</div>
In first case, Why absolutely positioned parent element(div
) width is zero?