2010-04-02 81 views
1

無論何時向下滾動頁面,我都希望在我的網頁上顯示標題DIV和頁腳DIV 總是CSS/HTML:如何用CSS模擬IFRAME?

如何做到這一點只用CSS(不含iframe)

例如:

<div id=header>Always display on top, regardless if you have scrolled down the page</div> 
<div id=main_content>...</div> 
<div id=footer>Always display on the bottom</div> 

回答

1

如果你能避免IE 6,那麼你可以使用position: fixed

喜歡的東西

<style type="text/css"> 
    #header { position: fixed; top: 0px; } 
    #main_content { height: 1200px; } 
    #footer { position: fixed; bottom: 0px; } 
</style> 
<div id=header> 
    Always display on top, regardless if you have scrolled down the page 
</div> 
<div id=main_content>...</div> 
<div id=footer> 
    Always display on the bottom 
</div> 

A Better Fixed Positioning for Internet Explorer 6

+0

連同'top:0;'表示頁眉,'bottom:0;'表示頁腳。 – 2010-04-02 04:07:46

0
#header { position: fixed; } 
#footer { position: fixed; } 

但請不要用這個。你的用戶會恨你並離開該網站。

0
#header{ 
left:0; 
top:0; 
height:100px; 
width:100%; 
position:fixed; 
z-index:2; 
background:grey; 
} 
#main_content{ 
margin-top:100px; 
margin-bottom:100px; 
height:1000px; 
} 
#footer{ 
bottom:0; 
left:0; 
height:100px; 
width:100%; 
position:fixed; 
z-index:2; 
background:grey; 
}