I am confused about position absolute and relative in CSS.
<div id="container" style="position:"relative"> <button style="position:"absolute"; left:10px;" > </div> In the above example, when I set position as absolute and left as 10px to button means it doesn't takes the position from browser window. Instead of this, it takes position from parent div (container) because container position is relative. Why?
When I set position absolute to any element it takes the position from browser window only. Why it checks the parent element and then positioning.
When I set position relative to any element means that time it will position based on parent element.
<p>Paragraph 1.</p> <p>Paragraph 2.</p> <p style="position: relative;left: 2em;">Paragraph 3.</p> In the above example, the third paragraph will be positioned 3em from the left side of the container element.
I have researched following links.
http://webdesign.about.com/od/advancedcss/a/aa061307.htm
http://www.barelyfitz.com/screencast/html-training/css/positioning/
absolute → takes position from browser window
relative → takes position from parent of an element