关于div相对定位和div绝对定位的说明实例 关于div相对定位和div绝对定位的说明实例 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=big5" /> <title>關於div相對定位和div絕對定位的說明實例</title> <style> body {margin: 30px; font-size:9pt;} .a, .b, .c, .d, .e { width: 100px; height: 100px; margin: 5 auto; color: #fff; background: #000; } .aa, .bb, .cc, .dd, .ee { left: 10px; width: 10px; height: 10px; overflow: hidden; background: #F90; } .b, .d, .e {position: relative;} .cc, .dd, .ee {position: absolute;} </style> </head> <body> <div class="a"> <div class="aa"></div> A:均不設置postion,一般嵌套關係 </div> <div class="b"> <div class="bb"></div> B:僅外div設置relative,一般嵌套關係 </div> <div class="c"> <div class="cc"></div> C:僅內div設置absolute,文檔中為嵌套關係,頁面中內div浮起[非float],相對於頁面定位,與外div無關。 </div> <div class="d" style="background:#ff0000"> <div class="dd" ></div> D:外div設置relative,內div設置absolute,內div浮起來並相對於外div定位 </div> <div class="d" style="background:#ff0000"> <div class="dd" style="position:relative"></div> D:外div設置relative,內div設置relative,內div浮起來並相對於外div定位 </div> <div class="e"> <div class="ee" style="left: -10px;"></div> E:這個是說明邊界問題。-10 != 反向10px間距 </div> </body> </html> 相关文章: