我有一个网站与以下结构:

<div id="header"></div>

<div id="main">
  <div id="navigation"></div>
  <div id="content"></div>
</div>

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

导航栏在左边,内容div在右边。内容div的信息是通过PHP拉入的,因此每次都是不同的。

我怎样才能垂直缩放导航,使其高度与内容div的高度相同,无论哪个页面被加载?


当前回答

我的解决方案:

$(window).resize(function() {
   $('#div_to_occupy_the_rest').height(
        $(window).height() - $('#div_to_occupy_the_rest').offset().top
    );
});

其他回答

(在另一个回答中提到了Dmity的Less代码)我猜这是某种“伪代码”?

据我所知,尝试使用人造柱技术应该可以做到这一点。

http://www.alistapart.com/articles/fauxcolumns/

希望这对你有所帮助。

我可能有点晚了,但我找到了一个周围的工作,可能是一个hack。 首先给父层一个弯曲和100vh的高度

就像这样:

.parent {
   display: flex;
   justify-content: center;
   align-items: center;
   height: 100vh;/* Can be less depends on the container, basically this forces the element to expand */
}

高度:< % >将只工作,如果你所有的父节点都具有指定的百分比高度和固定的高度(像素,ems等)在顶层。这样,高度就会随你的喜好而下降。

您可以像前面提到的@Travis那样为html和body元素指定100%,以使页面高度向下级联到节点。

对于父节点:

display: flex;

您应该添加一些前缀,例如http://css-tricks.com/using-flexbox/。

正如@Adam Garner所指出的,align-items:拉伸;不需要。它的用法也适用于父母,而不是孩子。如果你想定义儿童拉伸,你使用align-self。

.parent { 背景:红色; 填充:10 px; 显示:flex; } .other-child { 宽度:100 px; 背景:黄色; 身高:150 px; 填充:.5rem; } .child { 宽度:100 px; 背景:蓝色; } < div class = "父" > < div class = "另一个孩子“> 仅用于拉伸父节点 < / div > < div class = "孩子" > < / div > < / div >

我发现,设置两列显示:table-cell;代替float: left;工作得很好。