

把body看作是一個(gè)容器,做為內(nèi)部對(duì)象的上層標(biāo)簽,他的高度設(shè)置為100%是關(guān)鍵。
最基本的例子
| 以下是引用片段: * { margin:0; padding:0; border:0;} html,body { height:100%;} /* 同時(shí)設(shè)置html是為了兼容FF */ #box_2 { height:100%; background:#000;} |
重疊絕對(duì)高度效果
| 以下是引用片段: #box_1 { position:absolute; top:0; left:0; width:100%; height:50px; background:#f00; z-index:2;} #box_2 { position:absolute; left:0; top:0; width:100%; height:100%; background:#000; z-index:1;} |
縱向相對(duì)高度效果
| 以下是引用片段: #box_1 { position:absolute; top:0; left:0; width:100%; height:30%; background:#f00; z-index:2;} #box_2 { position:absolute; left:0; top:30%; width:100%; height:70%; background:#000; z-index:1;} |
橫向相對(duì)寬度效果
| 以下是引用片段: #box_1 { position:absolute; top:0; left:0; width:40%; height:100%; background:#f00; z-index:2;} #box_2 { position:absolute; top:0; right:0; width:60%; height:100%; background:#000; z-index:1;} |
這種布局是不需要float的,還可以有很多變化:
1、N列布局
2、N行布局
3、N列加N行交叉布局
值得注意的是在FF下瀏覽相對(duì)大小容器頁(yè)面時(shí),調(diào)整窗口大小的同時(shí)容器大小進(jìn)行實(shí)時(shí)調(diào)整,而IE只會(huì)在窗口調(diào)整完畢后才出效果。
您發(fā)布的評(píng)論即表示同意遵守以下條款:
一、不得利用本站危害國(guó)家安全、泄露國(guó)家秘密,不得侵犯國(guó)家、社會(huì)、集體和公民的合法權(quán)益;
二、不得發(fā)布國(guó)家法律、法規(guī)明令禁止的內(nèi)容;互相尊重,對(duì)自己在本站的言論和行為負(fù)責(zé);
三、本站對(duì)您所發(fā)布內(nèi)容擁有處置權(quán)。
蘇公網(wǎng)安備 32070502010230號(hào)