国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 開發(fā) > CSS > 正文

CSS布局實(shí)例:上中下三行,中間自適應(yīng)

2024-07-11 08:43:32
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

  上中下三行布局,上下定高,中間欄自適應(yīng)瀏覽器高度,且內(nèi)容垂直居中。
  firefox 2.0 / win ie 6/ win ie 7 /opera 8.5 cn/win safari 測(cè)試通過(guò)。
  對(duì)于非ie內(nèi)核瀏覽器,通過(guò)設(shè)定display:table、display:table-row和display:table-cell來(lái)模擬表格的表現(xiàn)形式。
  最外層#box { display:table; },高度100%,其子層#header/#main/#footer為{ display:table-row; },因此可以模擬表格的行效果,上下定高,則中間不定高的層自適應(yīng)高度。
  #wrap層為{ display:table-cell; }模擬單元格,因此可以設(shè)定{ vertical-align:middle; },垂直居中。
  由于Win IE不支持{ display:table; },因此,只能采取定位的方式實(shí)現(xiàn)。<!--[if IE]>內(nèi)是針對(duì)ie的設(shè)定。
以下為引用的內(nèi)容:

<!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=gb2312" />
<title>上中下三行布局,上下定高,中間欄自適應(yīng)瀏覽器高度,且內(nèi)容垂直居中</title>
<style type="text/css">
* {
margin:0;
padding:0;
}
html,
body,
#box {
height:100%;
font:small/1.5 "宋體", serif;
}
body {
text-align:center;
}
#box {
text-align:left;
background:#666;
display:table;
width:80%;
margin:0 auto;
position:relative;
}
#box > div {
display:table-row;
}
#header,
#footer {
background:#fcc;
height:50px;
}
#main {
background:#ccf;
}
#main #wrap {
display:table-cell;
background:#ffc;
vertical-align:middle;
}
#text {
text-align:center;
}
</style>
<!--[if IE]>
<style type="text/css">
#header,
#footer {
width:100%;
z-index:3;
position:absolute;
}
#footer {
bottom:0;
}
#main {
height:100%;
z-index:1;
position:relative;
}
#main #wrap {
position:absolute;
top:50%;
width:100%;
text-align:left;
}
#main #text {
position:relative;
width:100%;
top:-50%;
background:#ccc;
}
</style>
<![endif]-->
</head>
<body>
<div id="box">
<div id="header">header</div>
<div id="main">
<div id="wrap">
<div id="text">
<p>內(nèi)容內(nèi)容</p>
<p>內(nèi)容內(nèi)容</p>
<p>內(nèi)容內(nèi)容</p>
<p>內(nèi)容內(nèi)容</p>
<p>內(nèi)容內(nèi)容</p>
<p>內(nèi)容內(nèi)容</p>
<p>內(nèi)容內(nèi)容</p>
<p>內(nèi)容內(nèi)容</p>
<p>內(nèi)容內(nèi)容</p>
<p>內(nèi)容內(nèi)容</p>
<p>內(nèi)容內(nèi)容</p>
<p>內(nèi)容內(nèi)容</p>
<p>內(nèi)容內(nèi)容</p>
<p>內(nèi)容內(nèi)容</p>
</div>
</div>
</div>
<div id="footer">footer</div>
</div>
</body>
</html>

[Ctrl A 全部選擇 提示:你可先修改部分代碼,再按運(yùn)行]
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 南陵县| 新田县| 德格县| 富宁县| 安福县| 临漳县| 浦县| 华坪县| 大石桥市| 疏勒县| 化隆| 乃东县| 襄城县| 秭归县| 富蕴县| 滨州市| 尼玛县| 祁门县| 海淀区| 郯城县| 新津县| 读书| 抚远县| 临清市| 南阳市| 瑞安市| 五河县| 苗栗县| 都江堰市| 仲巴县| 玉山县| 开化县| 舟曲县| 邵阳县| 苏尼特右旗| 富平县| 应用必备| 宝山区| 壶关县| 通河县| 徐汇区|