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

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

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


当前回答

你没有提到一些重要的细节,比如:

布局是否固定宽度?两列中的一列或两列的宽度是否固定?

有一种可能性:

身体第二部分{边距:0;边框:0无;填充:0;}html,身体#包装,#左侧,#权利{高度:100%;最小高度:100%;}#包装,包装{边距:0自动;溢出:隐藏;宽度:960px;/*宽度可选*/}#左侧{背景:黄色;浮动:左侧;宽度:360px;/*宽度可选,但建议使用*/}#权利{背景:灰色;左边距:360px;/*必须与以前的宽度一致*/}<html><head><title>示例</title></head><body><div id=“wrapper”><div id=“left”>左边</div><div id=“right”></div></div></body></html>

这取决于哪些柱需要固定,哪些柱是液体。您也可以使用绝对定位来实现这一点,但我通常使用浮点数来获得更好的结果(特别是在跨浏览器方面)。

其他回答

您可以使用显示器:flex和高度:100vh

html,正文{高度:100%;边距:0px;}正文{显示:柔性;}.左,.右{挠曲:1;}.左侧{背景:橙色;}.对{背景:青色;}<div class=“left”>左</div><div class=“right”>右</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 */
}

摘自本页。

您可以在CSS中使用查看端口单元:

HTML格式:

<div id="my-div">Hello World!</div>

CSS:

#my-div {
    height: 100vh; /* vh stands for view-port height, and 1vh is 1% of screen height */
}

现在使用高度:100vh;对于固定的窗口高度:

<style>
    .header-top {
        height: 100vh;
        background: #000;
        color: #FFF;
        display: flex;
        align-items: center;
        padding: 10px;
        justify-content: space-around;
    }

    .header-top ul {
        list-style: none;
        padding: 0;
        margin: 0;
        display: flex;
        align-items: center;
    }

    .header-top ul li {
        padding:0px 10px;
    }
</style>

<div class="header-top">
    <div class="logo">Hello</div>
    <ul>
        <li>Menu</li>
        <li>About Us</li>
        <li>Contact US</li>
        <li>Login</li>
    </ul>
</div>

添加最小高度:100%,不指定高度(或将其设置为自动)。它完全帮了我的忙:

.container{     
    margin: auto;
    background-color: #909090;
    width: 60%;
    padding: none;
    min-height: 100%;
}