在绝对 div 上设置高度 100% [英] Set height 100% on absolute div

查看:31
本文介绍了在绝对 div 上设置高度 100%的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了覆盖 100% 高度 div 的问题.我可以使用固定位置来解决封面问题,但这并不是我真正想要的,因为您应该能够向下滚动封面"> 这样分辨率低于我的人就可以看到整个内容.

I am facing a problem with overlaying a 100% height div. I could use position fixed to solve the cover, but that's not really what I want because you should be able to scroll down on the 'cover' > so people with lower resolutions than mine can see the entire content.

代码示例:

HTML

<body>
<div>Overlay example text</div>
</body>

CSS

body {
    float: left;
    height: 3000px;
    width: 100%;
}
body div {
    position: absolute;
    height: 100%;
    width: 100%;
    background-color: yellow;
}

问题: div 的高度 100% 只包含 100% 的 webbrowser/viewport,但我希望它覆盖整个身体.

The problem: The div's height 100% only contains 100% of the webbrowser/viewport, but I want it to cover the entire body.

提前致谢:)

推荐答案

http://jsbin.com/ubalax/1/edit.你可以在这里看到结果

http://jsbin.com/ubalax/1/edit .You can see the results here

body {
    position: relative;
    float: left;
    height: 3000px;
    width: 100%;
}
body div {
    position: absolute;
    height: 100%;
    width: 100%;
    top:0;
    left:0;
    background-color: yellow;
}

这篇关于在绝对 div 上设置高度 100%的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆