Div + CSS page layout, the appropriate use of absolute and relative, can give the layout to bring unexpected effects and convenience, to achieve twice the effort, recently in an article on the use of absolute and relative, but the explanation is not comprehensive, not easy to read. Below I try to write down some of my views, I hope to help you ...
To explain the relationship between the two, need to cooperate with examples, please see the example first:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<title>div + CSS Example, wayhome ' s blog</title>
<style type= "Text/css" >
<!--
body,td,th{font-family:verdana;font-size:9px;}
-->
</style>
<body>
<div style= "Position:absolute; top:5px; right:20px; width:200px; height:180px; Background: #00FF00; " >
Position:absolute;<br/>
Top:5px;<br/>
Right:20px;<br/>
<div style= "Position:absolute; left:20px; bottom:10px; width:100px; height:100px; Background: #00FFFF; " >
Position:absolute;<br/>
Left:20px;<br/>
Bottom:10px;<br/>
</div>
</div>
<div style= "Position:absolute; top:5px; left:5px; width:100px; height:100px; Background: #00FF00; " >
Position:absolute;<br/>
Top:5px;<br/>
Left:5px;<br/>
</div>
<div style= "position:relative; left:150px; width:300px; height:50px; Background: #FF9933; " >
Position:relative;<br/>
Left:150px;<br/>
<br/>
width:300px; height:50px; <br/>
</div>
<div style= "Text-align:center; Background: #ccc; " >
<div style= "margin:0 auto; width:600px; Background: #FF66CC; Text-align:left; " >
<p>1</p>
<p>2</p>
<p>3</p>
<p>4</p>
<p>5</p>
<div style= "padding:20px 0 0 20px; Background: #FFFF00; " >
padding:20px 0 0 20px;
<div style= "Position:absolute; width:100px; height:100px; Background: #FF0000; " >position: <span style= "color: #fff; ">absolute</span>;</div>
<div style= "position:relative; left:200px; width:500px; height:300px; Background: #FF9933; " >
Position: <span style= "Color:blue;" >relative</span>;<br/>
Left:200px;<br/>
<br/>
Width:300px;<br/>
Height:300px;<br/>
<div style= "Position:absolute; top:20px; right:20px; width:100px; height:100px; Background: #00FFFF; " >
Position:absolute;<br/>
Top:20px;<br/>
RIGHT:20PX;<BR/></div>
<div style= "Position:absolute; bottom:20px; left:20px; width:100px; height:100px; Background: #00FFFF; " >
Position:absolute;<br/>
Bottom:20px;<br/>
Left:20px;<br/>
</div>
</div>
</div>
</div>
</div>
</body>
[1] [2] Next page