<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8"> <title>float演練</title> <style> #div1 { border: 2px; background-color: deeppink; width: 800px; height: 600px; position: relative; } /*當元素絕對定位后,會脫離文檔流,這時候用清除浮動的方式實現不用*/ #div2 { border: 2px; background-color: sandybrown; width: 200px; height: 100px; position: absolute; left: 20px; top: 10px; } #div3 { border: 2px; background-color: darkred; width: 200px; height: 100px; } /*新建一個元素頂替因絕對定位失去的文檔流,大小,高度都一樣*/ #padding { border: 2px; /*background-color: red;*/ width: 200px; height: 100px; } </style> </head> <body> <div id="div1">div1 <div id="div2">div2</div> <div id="padding" style="clear: both"></div> <div id="div3">div3</div> </div> </body> </html>
float演練
div1
div2
div3
