五月综合缴情婷婷六月,色94色欧美sute亚洲线路二,日韩制服国产精品一区,色噜噜一区二区三区,香港三级午夜理伦三级三

您現(xiàn)在的位置: 365建站網(wǎng) > 365文章 > CSS布局實(shí)例:上中下三行 中間自適應(yīng)

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

文章來源:365jz.com     點(diǎn)擊數(shù):191    更新時(shí)間:2009-05-17 23:06   參與評論

CSS布局實(shí)例:上中下三行布局,上下定高,中間欄自適應(yīng)瀏覽器高度,且內(nèi)容垂直居中。本文代碼在firefox 2.0 / win ie 6/ win ie 7 /opera 8.5 cn/win safari 測試通過。對于非ie內(nèi)核瀏覽器,通過設(shè)定display:table、display:table-row和display:table-cell來模擬表格的表現(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)。內(nèi)是針對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> 

如對本文有疑問,請?zhí)峤坏浇涣髡搲?,廣大熱心網(wǎng)友會為你解答??! 點(diǎn)擊進(jìn)入論壇

發(fā)表評論 (191人查看,0條評論)
請自覺遵守互聯(lián)網(wǎng)相關(guān)的政策法規(guī),嚴(yán)禁發(fā)布色情、暴力、反動的言論。
昵稱:
最新評論
------分隔線----------------------------

其它欄目

· 建站教程
· 365學(xué)習(xí)

業(yè)務(wù)咨詢

· 技術(shù)支持
· 服務(wù)時(shí)間:9:00-18:00
365建站網(wǎng)二維碼

Powered by 365建站網(wǎng) RSS地圖 HTML地圖

copyright © 2013-2024 版權(quán)所有 鄂ICP備17013400號