fit wrapper to 100% width and height

I would like to create a div which fits the full height and width of the browser viewport. I just thought about simple css like:

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

but it does not work for the height. The #wrapper does not have any height. Why?

Thanks in advance.


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

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

or

html, body { height: 100% }

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

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


How about this:-

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

or

html { height: 100% }
body { height: 100% }
链接地址: http://www.djcxy.com/p/89410.html

上一篇: 为什么身体的高度不符合html的高度?

下一篇: 适合包装到100%的宽度和高度