2010-04-02 2 views
1

Я хочу иметь заголовок DIV и нижний колонтитул DIV всегда, отображаемый на моей веб-странице, независимо от того, когда вы прокручиваете страницу вниз.CSS/HTML: Как имитировать IFRAME с помощью CSS?

Как сделать это, используя только CSS (без IFrames)

Например:

<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;' для нижнего колонтитула. –

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; 
}