0

我有一个 HTML 页面并包含 3 个这样的 div: 链接

<div style="min-height:100%;">
        <div id="TopContent" style="display: inline-block; height: 100px; width: 100%; background-color: #CCDEBB;">
        </div>

        <div id="LeftContent" style="display: inline-block; width: 25%; border: 3px solid #DFE8F6;">

                </div>             

        <div id="RightContent" style="border: 3px solid #b8cfee; display: inline-block; float: right; width: 72%;">


        </div>

            </div>

我想根据页面高度值设置 LeftContent 和 RightContent 的高度值。我的意思是 LeftContent 和 RightContent 高度延伸到页面的末尾。

4

7 回答 7

1

我建议你使用类而不是 id。

HTML

<div class="content top"></div>
<div class="content left"></div>
<div class="content right"></div>

CSS

*{
  height:100%;
  width:100%;
  margin:0;
} /* instead of HTML and BODY attributes */

.content{
  display:inline-block;
  margin-right:-4px; /*to margin left div with the right one!*/
  margin-top:-4px; /*to margin left and right divs with the top one!*/
}

.left{
  height:calc(100% - 200px); /*use calc(100% - "top div height" */
  width:50%; /*choose your own width*/
  background-color:red;
}

.right {
  height: calc(100% - 200px); /*use calc(100% - "top div height" */
  width:50%; /*choose your own width*/
  background-color:green;
}

.top{
  width:100%;
  height:200px;
  background-color:blue;
}

希望这可以帮到你!(在http://codepen.io/utopy/pen/zcyti上查看更多信息)

于 2013-10-21T13:43:08.587 回答
1

使用计算();

#LeftContent{
float:left;
margin-right:3px;
height:calc(100% - 100px); //-100px because height of top bar is 100px

}

正确的内容也一样

于 2013-10-21T12:11:20.450 回答
1

您无法使用此 HTML 控制高度,但您可以使用 :before/:after 元素模拟此效果:

#LeftContent:after,
#RightContent:after{
    content:'';
    position:absolute;
    top:0;
    left:0;
    width:100%;
    height:9999px;
    z-index:-1;
    background:#DFE8F6;
}
#RightContent:after{background:#b8cfee;}

http://jsfiddle.net/EhnhZ/

于 2013-10-21T12:11:24.433 回答
0

喜欢这个演示吗?

只需添加float: left;到 LeftContent

于 2013-10-21T12:02:36.033 回答
0

我使用这个问题的答案建立了我的答案

<style>
    html, body {
    margin: 0;
    padding: 0;
    height: 100%;
}
</style>

<div style="min-height:100%;height:100%;">
    <div id="TopContent" style="height: 100px; width: 100%; background-color: #CCDEBB;">
    </div>

    <div id="LeftContent" style="min-height:100%;width: 25%; border: 3px solid #DFE8F6;float:left">    
    </div>             

    <div id="RightContent" style="min-height:100%;border: 3px solid #b8cfee; width:72%;float:right">
    </div>
</div>
于 2013-10-21T12:11:49.367 回答
0

目前您的解决方案将不起作用,这是因为网页documents呈现方式。

目前,从您的 HTML 来看,您当前的文档高度如下:

100px (from TopContent)

+ 3px (from LeftContent)

+ 3px (from RightContent)

因为document不需要大于106px(基于内容),所以document元素不会呈现更多。

您可以通过将 body/html CSS 属性设置为 100% 的高度来解决此问题。

使用以下 CSS 来执行此操作:

body,html {
    height:100%;
}

此外,您需要将容器 div 的高度设置为

<div style="height:100%;">

这是针对您的问题的示例JSFiddle

于 2013-10-21T12:12:56.610 回答
-2

您应该使用 jquery,在这种情况下设置 div 的高度

$(window).resize(function () {
 $('#LeftContent').css('height',$(window).height());
 $('#RightContent').css('height',$(window).height());
        });
于 2013-10-21T12:08:50.557 回答