2012-12-14 120 views
3

我有這樣的結構:使身體100%的高度

<body> 

    <div id="header">..</div> 

    <div id="content">..</div> 

    <div id="footer">..</div> 

</body> 

而這個CSS:

體{ 顏色:白色; font-family:'Play',sans-serif; max-width:2560px; margin:0 auto; min-width:960px; 身高:100%; 填充:0; }

#header { 
    position: relative; 
    overflow: hidden; 
    margin: 0 auto; 
    min-width: 960px; 
    height: 95px; 
    background-image: url("../images/header-bg.png"); 
} 

#content { 
    margin: 0 auto; 
    position: relative; 
    max-width: 1600px; 
    height:100%; 
    overflow:hidden; 
} 

#footer { 
    background-color: #009EDB; 
    background-image: url("../images/footer-bg.png"); 
    bottom: 0; 
    height: 30px; 
    margin: 0; 
    position: relative; 
    width: 100%; 

}​ 

但不是body高度的瀏覽器窗口100%。我的問題是什麼?謝謝。

jsFiddle

+1

您是否試過添加:'html {height:100%;寬度:100%; ''? – mqchen

+1

可能的重複[stackoverflow.com/questions/1575141/...](http://stackoverflow.com/questions/1575141/make-div-100-height-of-browser-window) – War10ck

回答

3

爲了使其發揮作用。您必須使父母<html>和子女<body>都具有100%的身高。

html, body { 
    height:100%; /*both html and body*/ 
} 
body { 
    margin: 0; /*reset default margin*/ 
}