標籤:布局 介面 html css
在html中引入css樣式,可以改變html的塊布局方式,使得介面的布局更加美觀。接下來看一個基礎布局的小例子:
<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>margin布局</title></head><style type="text/css">#container{width: 1002px;background: gray;}#header{height: 120px;background: orange;}#main{background: green;height: 600px;}#lside{width: 700px;height: 600px;float: left;background: pink;}.four{width: 130px;height: 280px;float: left;margin: 10px;background: black;}#rside{width: 302px;height: 600px;background: purple;float: right;}#footer{height: 120px;background: blue;}</style><body><div id="container"><div id="header"></div><div id="main"><div id="lside"><div class="four"></div><div class="four"></div><div class="four"></div><div class="four"></div></div><div id="rside"></div></div><div id="footer"></div></div></body></html>
效果如下:
在上面的布局中,我們主要使用margin屬性來對div進行布局,在實際中,感覺margin屬性主要適用於塊與塊之間的布局,當我們要對盒子中的內容進行布局的時候,我們可以使用盒子的另一個屬性:padding,這個屬性可以布局盒子內部的距離:
例如,我們加入padding屬性,並在四個div中加入一些文字內容:
:
注意,這裡在實際做的時候,因為加入了padding值,導致了div最後不能並排顯示在父div中,這裡還修改了div的寬度值,使第四個div不至於被擠到下面去。
感覺加入css樣式後,最近做的小demo跟以前只用html做的demo比起來,不僅布局上更加靈活多變,而且樣式設定也比較簡單了。
css+html簡單布局demo