在下面所示的标记中,我试图让内容div一直延伸到页面的底部,但只有在有内容要显示时才会拉伸。我想这样做的原因是,即使没有任何内容显示,垂直边界仍然出现在页面下方。

下面是我的演示:

body { font-family: Trebuchet MS, Verdana, MS Sans Serif; font-size:0.9em; margin:0; padding:0; } div#header { width: 100%; height: 100px; } #header a { background-position: 100px 30px; background: transparent url(site-style-images/sitelogo.jpg) no-repeat fixed 100px 30px; height: 80px; display: block; } #header, #menuwrapper { background-repeat: repeat; background-image: url(site-style-images/darkblue_background_color.jpg); } #menu #menuwrapper { height:25px; } div#menuwrapper { width:100% } #menu, #content { width:1024px; margin: 0 auto; } div#menu { height: 25px; background-color:#50657a; } <form id="form1"> <div id="header"> <a title="Home" href="index.html" /> </div> <div id="menuwrapper"> <div id="menu"> </div> </div> <div id="content"> </div> </form>


当前回答

我没有代码,但我知道我这样做了一次使用高度:1000px和margin-bottom: -1000px的组合;试试。

其他回答

我没有代码,但我知道我这样做了一次使用高度:1000px和margin-bottom: -1000px的组合;试试。

不是所有浏览器都支持min-height属性。如果你需要你的#content在较长的页面上扩展它的高度,height属性会缩短它。

这是一个小技巧,但你可以在#content div中添加一个宽度为1px,高度为1000px的空div。这将迫使内容至少有1000px高,并且仍然允许更长的内容在需要时扩展高度

Try:

html, body {
    height: 102%;
}
.wrapper {
    position: relative;
    height: 100%;
    width: 100%;
}
.div {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 1000px;
    min-height: 100%;
}

还没测试过…

虽然它不像纯CSS那样优雅,但一小部分javascript可以帮助实现这一点:

<html>
<head>
<style type='text/css'>
    div {
        border: 1px solid #000000;
    } 
</style>
<script type='text/javascript'>

    function expandToWindow(element) {
         var margin = 10; 

         if (element.style.height < window.innerHeight) { 
            element.style.height = window.innerHeight - (2 * margin) 
         }
    }


</script>
</head>
<body onload='expandToWindow(document.getElementById("content"));'>
<div id='content'>Hello World</div>
</body>
</html>

试试下面的css规则:

#content {
    min-height: 600px;
    height: auto !important;
    height: 600px;
}

改变高度以适应你的页面。为了跨浏览器兼容性,高度提到了两次。