容器高度100%的絕對定位布局
更新時間:2006年07月31日 00:00:00 作者:
容器高度100%是經(jīng)常用到的需求,任何容器都可以實現(xiàn),而且不需要嵌套關系。
把body看作是一個容器,做為內(nèi)部對象的上層標簽,他的高度設置為100%是關鍵。
最基本的例子
* { margin:0; padding:0; border:0;}
html,body { height:100%;} /* 同時設置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;}
縱向相對高度效果
#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;}
橫向相對寬度效果
#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下瀏覽相對大小容器頁面時,調(diào)整窗口大小的同時容器大小進行實時調(diào)整,而IE只會在窗口調(diào)整完畢后才出效果。
IE5.0 / IE5.5 / IE6.0和FF1.5測試通過
相關文章
使用#default#userdata組件實現(xiàn)的可記憶內(nèi)容的編輯器
使用#default#userdata組件實現(xiàn)的可記憶內(nèi)容的編輯器...2006-08-08CSS3實例分享之多重背景的實現(xiàn)(Multiple backgrounds)
對于背景屬性background-image大家應該已經(jīng)很熟悉了,在CSS2中與它相關的屬性還有background-repeat(設置背景是否重復及重復的方式)、background-position(設置背景圖片在容器中的位置)、background-attachment(設置背景是否隨頁面一起滾動),通過這些屬性來控制背景圖片在容器中如何顯示,但我們也只能為容器提供一張背景圖片,如果我們想讓一個容器的背景用多張圖片實現(xiàn),那么我們該如何去做呢?再在容器里添加一些無用的元素嗎?2014-05-05CSS濾鏡示范(filter)附源代碼(靜態(tài)濾鏡)
CSS濾鏡示范(filter)附源代碼(靜態(tài)濾鏡)...2006-08-08