Q: What's the difference between absolute and relative positioning?
A: Setting the positioning as
absolute allows you to specify a new positioning context for an element relative to the positioning context of it's parent element. This removes the absolutely positioned element from the normal flow of the document.
Setting the positioning as
relative positions the element relative to it's place in the normal document flow.
e.g.
In this example the first div element is positioned 50px from the left and 125px down from the base point (parent). The second div is contained within the first, so its positioning is also determined by the first div element's base point. It therefore occupies the same space. This example creates a new positioning context as the elements are absolutely positioned outside the documents normal flow.
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Positioning</title>
<meta http-equiv="Content-Type" content="text/html; charset=shift_jis" />
</head>
<body>
<h1 style="border: 1px solid #000;">Header</h1>
<div style="position: absolute; left: 50px; top: 125px; border: 1px solid #000; width: 200px;">
<div style="position: absolute; left: 0; top: 0; border: 1px solid #000; width: 198px;">
This is the text.
</div>
</div>
</body>
</html>
In this next example, the second div element is positioned relatively. It is placed 120px from the left and 150px from the top of the position it would occupy in the normal flow of the document.
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Positioning</title>
<meta http-equiv="Content-Type" content="text/html; charset=shift_jis" />
</head>
<body>
<h1 style="border: 1px solid #000;">Header</h1>
<div style="position: absolute; left: 50px; top: 125px; border: 1px solid #000; width: 200px;">
This is text for the first.
</div>
<div style="position: relative; left: 120px; top: 150px; border: 1px solid #000; width: 198px;">
This is the text for the second.
</div>
</body>
</html>
Try experimenting with the left and top setting of the relatively positioned div.
REMEMBER: it's left and top settings are relative to the elements position in the normal flow of the document. In other words, if you were to change these settings to 0 for both left and top, the second div would then appear after the header element and before the first div. This can occur because the first div is absolutely positioned, and is therefore no longer a part of the normal flow of the document.
These settings allow you to overlap elements on the screen. When two elements overlap, you need to decide which of these takes precedence. In other words, which of the two elements appears "on top" and which appears "behind". This is achieved using the
z-index selector.
In this example the second div takes precedence because it's z-index value is higher than that of the first div.
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Positioning</title>
<meta http-equiv="Content-Type" content="text/html; charset=shift_jis" />
</head>
<body>
<h1 style="border: 1px solid #000;">Header</h1>
<div style="position: absolute; left: 50px; top: 50px; border: 1px solid #000; width: 200px; background-color: #aff;z-index:1;">
This is text for the first.
</div>
<div style="position: relative; left: 0; top: 0; border: 1px solid #000; width: 198px; background-color: #ffa;z-index:2;">
This is the text for the second.
</div>
</body>
</html>
I hope this makes sense to you

It's my first tutorial.