在DIV里面的DIV内部DIV 100%高度

时间:2011-01-24 21:53:54

标签: css-float

我知道之前可能已经问过这个问题了,我尝试了几种不同的方法,但我似乎无法让我的内部DIV扩展到视口的整个高度。

这是我的CSS:

html, body {margin: 0 auto; padding: 0; height: auto !important; min-height: 100%; height: 100%;}

p, h1 {font-family:"lucida grande",tahoma,verdana,arial,sans-serif;font-size:11px;text-align:left;margin:1em 0}

 /*******************************************************************************
Primary Container Structure
********************************************************************************/
#container {width: 100%; margin: 0px 0px; background-color: #fff; color: #333;}

#top {padding: .5em; background-color: #3b5998; color:White;}
#top h1 {padding: 0; margin: 0;}

#subcontainer {width: 90%; margin: 0px auto; line-height: 130%;}

#rightnav {height:100%; float: right; width: 244px; margin: 0; padding: 1em; max-width:244px;}
#content {height:100%; border-left: 1px solid gray; margin-right: 284px; border-right: 1px solid gray; padding: 1em;}

#leftnav p, #rightnav p {margin: 0 0 1em 0;}
#content h2 {margin: 0 0 .5em 0;}

#footer {clear: both; margin: 0; padding: .5em; color: #333; background-color: #ddd; border-top: 1px solid gray;}

这是我的HTML:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="SHELL.aspx.cs" Inherits="SHELL" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>

    <link rel="stylesheet" type="text/css" href="css/base.css">  

</head>
<body>
<form id="form1" runat="server">
<div id="container">

    <div id="top">
        <h1>NAME</h1>
    </div>
    <div id="subcontainer">



        <div id="rightnav">
            <p>
            Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut.
            </p>
        </div>

        <div id="content">
            <h2>Subheading</h2>
            <p>
            Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.
            </p>
            <p>
            Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
            </p>
        </div>


    </div>
    <div id="footer">
        Footer
    </div>

</div>
</form>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

您不能让中间容器首先计算页脚高度,然后从它的100%高度父容器中减去它。

您只有当前加价的选项是:

  1. 使用javascript(不必要的开销)
  2. 使用表格(可能不是一个好主意)
  3. 以下是我必须重新安排代码的选项:Code Here
  4. 我使你的页脚和页脚都能正常工作,但它需要你使用faux columns,这是一种常见的技巧,可用于底部粘贴页脚。有关示例,请参阅this

    简单地说,在主体上指定左边框图像到repeat-y,在子容器上指定右边框图像到repeat-y,右边背景。