2014-01-21 71 views
1

這是我的代碼,當頁面有更多的內容,當我們滾動頭移動過,然後我試圖使頭fixed的位置,但隨後頁腳不會粘底:/如何獲得固定頭與CSS?

html,body 
{ 
    margin: 0px; 
    height:100%; 
    min-height: 100%; 
    top: 0; 
    width: 100%; 
    position: absolute; 
} 
header 
{ 
    width: 100%; 
    background-color: #000000; 
    height: 8%; 
    min-height: 8%; 
} 
#container 
{ 
    min-height: 85%; 
    margin-top: 0.5%; 
} 
footer 
{ 
    bottom: 0; 
    background-color: #000000; 
    width: 100%; 
    height: 6%; 
    min-height: 6%; 
    position: relative; 

} 

回答

2

套裝position:fixed到footter

header 
{ 
    width: 100%; 
    background-color: #000000; 
    height: 8%; 
    min-height: 8%; 
    z-index:1000; 
    position:fixed; 
    /*.........^........*/ 
    top:0; 
} 
footer{ 
    bottom: 0; 
    background-color: #000000; 
    z-index:1000; 
    width: 100%; 
    height: 6%; 
    min-height: 6%; 
    position:fixed; 
    /*.........^........*/  
} 

Fiddle Demo

+0

的OP詢問'固定'**標題**,而不是_footer_。 – Vucko

+0

@PranavRam它不是我想要修復的頁腳我想修復的頁眉 – maniteja

1
footer 
    { 
     position: fixed; 
     z-index: 300; 
     bottom: 0px; 
     left: 0px; 
     background-color: #000000; 
     width: 100%; 
     height: 6%; 
     min-height: 6%; 
    } 
1

JsFiddle

header 
{ 
    width: 100%; 
    background-color: #000000; 
    height: 8%; 
    min-height: 8%; 
    position: fixed; 
    top: 0; 
} 
footer 
{ 
    bottom: 0; 
    background-color: #000000; 
    width: 100%; 
    height: 6%; 
    min-height: 6%; 
    position: absolute; 
    color: #FFFFFF; 
} 

在這裏,我提到height: 1000px;的理解......你可以改變它...

0

試試這個代碼:

DEMO

header 
{ 
    width: 100%; 
    background-color: #000000; 
    height: 8%; 
    min-height: 8%; 
    top: 0; 
    position: fixed; 
} 
footer 
{ 
    bottom: 0; 
    background-color: #000000; 
    width: 100%; 
    height: 6%; 
    min-height: 6%; 
    position: absolute; 

}