html - 使 wrapper 适合 100% 的宽度和高度

标签 html css

我想创建一个适合浏览器视口(viewport)的整个高度和宽度的 div。我只是想过简单的 css,比如:

#wrapper { width: 100%;
           height: 100%;
           background-color: red;
}

但它不适用于高度。 #wrapper 没有任何高度。为什么?

提前致谢。

最佳答案

#wrapper {
    position: absolute;
    width: 100%;
    height: 100%;
    background-color: red;
}

http://fiddle.jshell.net/zDuWh/

html, body { height: 100% }

#wrapper {
    width: 100%;
    height: 100%;
    background-color: red;
}

http://fiddle.jshell.net/VJv6h/

关于html - 使 wrapper 适合 100% 的宽度和高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18579903/

相关文章:

javascript - 在 Angular 路由/ View 加载后加载 jQuery 脚本

html - 加载页面时 UIWebView 白色闪烁

javascript - HTML 从 Iframe 中删除背景

javascript - 为什么设置 optionsValue 会中断 Knockout 更新?

html - 将 <td> 的元素始终放在顶部而不是中心

javascript - jQuery .css() 不会改变元素背景颜色

jquery - 用 CSS3 过渡替换 jQuery 幻灯片效果

html - Css 将侧边栏内容移到左侧

javascript - consolidate javascript - 用于显示内容的悬停导航

javascript - 使前两列粘在表格中