CSS樣式position屬性的一個(gè)小實(shí)例:z方向三層布局分析
發(fā)布時(shí)間:2012-12-07 15:34:59 作者:佚名
我要評(píng)論

使用CSS樣式中的position屬性實(shí)現(xiàn)z方向三層布局效果,本文甚是疑惑,于是乎搜集整理一番,曬出代碼和大家分享一下
CSS樣式position的一個(gè)小實(shí)例代碼如下:
<!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=utf-8" />
<title>CSS樣式position的一個(gè)小實(shí)例:z方向三層布局-成功志(www.ok12.net)</title>
</head>
<body>
<div style="width:400px; height:400px; background:#666; border:#9FF 1px solid;margin:0 auto; color:#9FF ">
我是最底層
<div style="position:relative; background:#969;width:300px; height:300px; border:1px #fff solid ;margin:0 auto; margin-top:30px; color:#fff">
<div style="width:300px; height:300px; background:#099; margin:0 auto; ">我是中間層</div>
<div style="position:absolute; top:0; width:100px; height:100px; background:#CCF; margin:100px; color:#444; border:#444 1px solid">我是最頂層</div>
</div>
</div>
</body>
</html>
最終效果:

另一個(gè)示例:
<!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=utf-8" />
<title>另一個(gè)展示</title>
</head>
<body>
<div style="width:220px; height:220px;background:#369; padding:10px">
<div style="position:relative;margin:10px;">
<div style="background:#CCC; width:200px; height:200px; "></div>
<div style="background:#666; width:180px; height:180px; position:absolute; top:0; margin:10px">
<div style="width:160px; height:160px; background:#f00; margin:10px"></div></div>
</div>
</div>
<div><embed src="http://static.youku.com/v1.0.0149/v/swf/qplayer_rtmp.swf?XNDQ1NzEzNjgw&winType=adshow&isAutoPlay=true" quality="high" width="寬度" height="高度" align="middle" type="application/x-shockwave-flash"></embed></div>
</body>
</html>
復(fù)制代碼
代碼如下:<!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=utf-8" />
<title>CSS樣式position的一個(gè)小實(shí)例:z方向三層布局-成功志(www.ok12.net)</title>
</head>
<body>
<div style="width:400px; height:400px; background:#666; border:#9FF 1px solid;margin:0 auto; color:#9FF ">
我是最底層
<div style="position:relative; background:#969;width:300px; height:300px; border:1px #fff solid ;margin:0 auto; margin-top:30px; color:#fff">
<div style="width:300px; height:300px; background:#099; margin:0 auto; ">我是中間層</div>
<div style="position:absolute; top:0; width:100px; height:100px; background:#CCF; margin:100px; color:#444; border:#444 1px solid">我是最頂層</div>
</div>
</div>
</body>
</html>
最終效果:

另一個(gè)示例:
復(fù)制代碼
代碼如下:<!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=utf-8" />
<title>另一個(gè)展示</title>
</head>
<body>
<div style="width:220px; height:220px;background:#369; padding:10px">
<div style="position:relative;margin:10px;">
<div style="background:#CCC; width:200px; height:200px; "></div>
<div style="background:#666; width:180px; height:180px; position:absolute; top:0; margin:10px">
<div style="width:160px; height:160px; background:#f00; margin:10px"></div></div>
</div>
</div>
<div><embed src="http://static.youku.com/v1.0.0149/v/swf/qplayer_rtmp.swf?XNDQ1NzEzNjgw&winType=adshow&isAutoPlay=true" quality="high" width="寬度" height="高度" align="middle" type="application/x-shockwave-flash"></embed></div>
</body>
</html>
相關(guān)文章
- 這篇文章主要介紹了CSS中的 position屬性sticky的相關(guān)知識(shí),本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-03-12
css position屬性為absolute時(shí)其百分值的計(jì)算
這篇文章主要介紹了css position屬性為absolute時(shí)其百分值的計(jì)算,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小2019-08-06- 這篇文章主要介紹了詳解CSS中position屬性介紹(新增sticky) 的相關(guān)資料,position的含義是指定位類(lèi)型,取值類(lèi)型可以有:static、relative、absolute、fixed、inherit和stic2018-12-17
- 這篇文章主要介紹了css中的position屬性值的探究(小結(jié))的相關(guān)資料,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-09-25
css關(guān)于position屬性的用法詳解(絕對(duì)定位和相對(duì)定位的混淆)
下面小編就為大家?guī)?lái)一篇css關(guān)于position屬性的用法詳解(絕對(duì)定位和相對(duì)定位的混淆)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-09-08淺談CSS中display/float/position屬性值的相互影響
下面小編就為大家?guī)?lái)一篇淺談CSS中display/float/position屬性值的相互影響。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-08-17- 這篇文章主要介紹了圖解CSS中position屬性的定位用法,重點(diǎn)講解了相對(duì)定位和絕對(duì)定位在頁(yè)面布局中的作用,需要的朋友可以參考下2016-04-28
- 這篇文章主要介紹了CSS的position屬性的完全解析,包括position和overflow在一些相似使用方面的對(duì)比,需要的朋友可以參考下2015-11-06
- 這篇文章主要介紹了CSS 中的position屬性實(shí)例詳解,定位屬性position有4個(gè)值,分別是靜態(tài)定位(static)、相對(duì)定位(relative)、絕對(duì)定位(absolute)和固定定位(fixed)2023-09-04