<div id="parent"> <div id="sub1">sub1</div> <div id="sub2">sub2</div></div>
sub1 and sub2 are of the same level relationship, parent is their parent element.
Relative positioning refers to the positioning relative to the original position of this element, and will occupy the original position.
The so-called original position refers to its position when the relative attribute is not set (that is, the position when the static attribute is used)
The relative offset is relative to the upper left side of the margin.
For example, after setting the relative attribute to sub1, it will be offset according to the top, right, bottom, and left attributes, while the position of sub2 remains unchanged (sub1 will occupy the original position)
If you set the relative attribute to sub2, it will also be offset relative to its original position (the sub2 position will still be occupied)
Absolute positioning is based on the upper left corner of the padding of the most recently positioned parent object. It is basically divided into the following two situations:
For example, sub1 Set absolute. If the parent element of sub1 (parent or its parent element) is set to absolute or relative, then sub1 will be positioned relative to the parent element. If the parent element is not set to absolute or relative, then sub1 is positioned relative to the body.At this time, since the position of sub1 is "vacated", sub2 will move to the position of sub1 (you can also understand that sub1 floats, which is called a layer in Dreamweaver), and its document flow will be based on parent.
If absolute is set to sub2, it will also be relative to parent.
fixed is a special absolute, that is, fixed always uses the body as the positioning object and is positioned according to the browser window.
The default value of position. Generally, when the position attribute is not set, it will be arranged according to the normal document flow.
Reference:
http://www.cnblogs.com/Zigzag/archive/2009/02/19/position.html
http://www.w3school .com.cn/css/css_positioning.asp