如何使身高真的100% [英] How to make the height REALLY 100%

查看:90
本文介绍了如何使身高真的100%的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在CSS中,当你将某些东西的宽度或高度设置为100%时,它确实只会将其设置为浏览器窗口的100%。有什么办法让它成为整个页面的100%吗?

让我改述:我希望这个元素(一个div)占据整个页面,不管你滚动多少。拥有100%大小和100%宽度的父元素不起作用,因为它们的处理方式相同。我开始认为我可能不得不使用JS来获取页面的高度,然后绝对定义它。

解决方案

只需将 position:fixed 应用于元素即可。
如果这是一个叠加:

  #overlay 
{
position:fixed;
top:0;
剩下:0;
宽度:100%;
身高:100%;
}

注意:IE6不支持修正


in CSS when you set something's width or height to 100% it really only sets it to 100% of the browser window. Is there any way to make it 100% of the whole page?

Let me rephrase: I want this element (a div) to take up the ENTIRE page, no matter how much you scroll. Having parent elements with 100% size and 100% width doesn't work because they are treated the same way. I'm beginning to think that I might have to use JS to get the height of the page and then absolutely define that.

解决方案

Simply apply position:fixed to the element. If this is an overlay:

#overlay 
{
    position: fixed;
    top: 0;
    left: 0;
    width:100%;
    height:100%; 
}

Note: fixed is not supported by IE6

这篇关于如何使身高真的100%的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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