容器高度100%的絕對(duì)定位布局
更新時(shí)間:2006年07月31日 00:00:00 作者:
容器高度100%是經(jīng)常用到的需求,任何容器都可以實(shí)現(xiàn),而且不需要嵌套關(guān)系。
把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;}
重疊定位效果
#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;}
#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:30%; height:100%; background:#f00; z-index:2;}
#box_2 { position:absolute; top:0; right:0; width:70%; height:100%; background:#000; z-index:1;}
#box_2 { position:absolute; top:0; right:0; width:70%; height:100%; background:#000; z-index:1;}
這種布局是不需要float的,還可以有很多變化:
1,N列布局
2,N行布局
3,N列加N行交叉布局
2,N行布局
3,N列加N行交叉布局
值得注意的是在FF下瀏覽相對(duì)大小容器頁(yè)面時(shí),調(diào)整窗口大小的同時(shí)容器大小進(jìn)行實(shí)時(shí)調(diào)整,而IE只會(huì)在窗口調(diào)整完畢后才出效果。
IE5.0 / IE5.5 / IE6.0和FF1.5測(cè)試通過(guò)
相關(guān)文章
使用#default#userdata組件實(shí)現(xiàn)的可記憶內(nèi)容的編輯器
使用#default#userdata組件實(shí)現(xiàn)的可記憶內(nèi)容的編輯器...2006-08-08
CSS3實(shí)例分享之多重背景的實(shí)現(xiàn)(Multiple backgrounds)
對(duì)于背景屬性background-image大家應(yīng)該已經(jīng)很熟悉了,在CSS2中與它相關(guān)的屬性還有background-repeat(設(shè)置背景是否重復(fù)及重復(fù)的方式)、background-position(設(shè)置背景圖片在容器中的位置)、background-attachment(設(shè)置背景是否隨頁(yè)面一起滾動(dòng)),通過(guò)這些屬性來(lái)控制背景圖片在容器中如何顯示,但我們也只能為容器提供一張背景圖片,如果我們想讓一個(gè)容器的背景用多張圖片實(shí)現(xiàn),那么我們?cè)撊绾稳プ瞿兀吭僭谌萜骼锾砑右恍o(wú)用的元素嗎?2014-05-05
CSS濾鏡示范(filter)附源代碼(靜態(tài)濾鏡)
CSS濾鏡示范(filter)附源代碼(靜態(tài)濾鏡)...2006-08-08

