3

我有这个结构:

<body>

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

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

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

</body>

这个CSS:

身体{颜色:白色;字体系列:“播放”,无衬线;最大宽度:2560px;边距:0 自动;最小宽度: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

4

3 回答 3

6

添加:

html {
    height: 100%;
}

到你的 CSS。

在这里查看更新 - http://jsfiddle.net/xkTpV/4/

于 2012-12-14T14:02:46.440 回答
4

为了使它工作。您必须让父母<html>和孩子<body>都拥有 100% 的高度。

html, body {
    height:100%; /*both html and body*/
}
body {
    margin: 0; /*reset default margin*/
}
于 2012-12-14T15:15:52.530 回答
1

尝试高度:100vh;

body { color: white; font-family: 'Play', sans-serif; max-width: 2560px; margin: 0; min-width: 960px; height:100vh; padding:0; }
于 2019-06-21T19:56:27.020 回答