一個div占據一行,怎樣實現布局中2個並列的div呢?本節將解決這個問題
(一)floate屬性可以使多個塊狀元素並列一行。
對前面的div元素設置浮動屬性后,當前面的div元素留有足夠的空白寬度時,后面的div元素將自動浮上來,和前面的div元素並列於一行.
(二)floate屬性值有如下取值
(1)left:塊狀元素向左移動
(2)right:塊狀元素向右移動
(3)none:塊狀元素不會浮動
(4)inherit:繼承父容器的值
(三)實例演示
<!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=gb2312" /> <title>無標題文檔</title> <style type="text/css"> *{margin:0px; padding:0px; } #one { width: 125px; background-color: #eee; height: 120px; border: 1px solid #000000; float:left; } #two { width: 200px; background-color: #eee; height: 120px; border: 1px solid #000000; } </style> </head> <body> <div id="one">第一div</div> <div id="two">第二個div</div> </body> </html>
無標題文檔
第一div
第二個div