我有一个包含两列的布局-左div和右div。

右侧的div具有灰色背景色,我需要它根据用户浏览器窗口的高度垂直展开。现在,背景色结束于该分区中的最后一段内容。

我尝试过高度:100%,最小高度:100%;,等


当前回答

只需使用“vh”单位而不是“px”,这意味着查看端口高度。

height: 100vh;

其他回答

如果你能绝对定位你的元素,

position: absolute;
top: 0;
bottom: 0;

会做到这一点。

其中一个选项是使用CSS表。它具有强大的浏览器支持,甚至可以在Internet Explorer 8中工作。

JSFiddle示例

html,正文{高度:100%;边距:0;}.容器{显示:表格;宽度:100%;高度:100%;}.左,.右{显示:表格单元格;宽度:50%;}.对{背景:灰色;}<div class=“container”><div class=“left”></div><div class=“right”></div></div>

这对我有用:

html, body {
    height: 100%; /* IMPORTANT!!! Stretches viewport to 100% */
}

#wrapper {
    min-height: 100%; /* Minimum height for a modern browser */
    height:auto !important; /* Important rule for a modern browser */
    height:100%; /* Minimum height for Internet Explorer */
    overflow: hidden !important; /* Firefox scroll-bar */
}

摘自本页。

这就是对我有用的:

<div style=“位置:固定;顶部:0px;左侧:0px,底部:0px

使用position:fixed而不是position:absolute,这样即使向下滚动分区也会扩展到屏幕的末尾。

如果要设置<div>或任何元素的高度,也应该将<body>和<html>的高度设置为100%。然后可以将元素的高度设置为100%:)

下面是一个示例:

body, html {
  height: 100%;
}

#right {
  height: 100%;
}