简体   繁体   English

展开子元素高度,以保留容器中剩余的空间

[英]Expand child element height for the space that is left in the container

Ok, so let me explain my problem here, i have a "typeSelector" that should be 100% of the page, and inside of it i want few divs that are "filters" and below them there should be a list. 好的,所以让我在这里解释我的问题,我有一个“ typeSelector”应该是页面的100%,并且在它里面我想要几个作为“ filters”的div,在它们下面应该有一个列表。 The filters could be 0, 1, or 2, so i don't know how much space will they take, and i want the list below them to expand for the space that is left in the container but when i put the list to be 100% the page shows a scrollbar... I want the page to fit 100% without showing a scrollbar and i want the list to expand for 100% of the height of the page and when there are more items the scrollbar should appear. 过滤器可能是0、1或2,所以我不知道它们会占用多少空间,我希望它们下面的列表可以扩展为容器中剩余的空间,但是当我将列表放在100%的页面显示一个滚动条...我希望页面适合100%而不显示滚动条,并且我希望列表扩展到页面高度的100%,并且当有更多项目时,滚动条应该出现。 When i remove the "filter" divs from the container the list is expanding good no matter how i resize the window, but when they are there everything is messed up. 当我从容器中删除“过滤器” div时,无论我如何调整窗口大小,列表都会很好地扩展,但是当它们在那里时,一切都搞砸了。 Here's the layout: 这是布局:

<div id="ftsContainer">
<div id="typeSelector">
    <div id="filtersContainer">
        <div class="filtersEtc">
            List filter here
        </div>
        <div class="filtersEtc">
            List filter here
        </div>
        <div class="filtersEtc">
            List filter here
        </div>
    </div>
          <ul id="selectorList">
            <li> test 1 </li>
            <li> test 2 </li>
            <li> test 3 </li>
            <li> test 4 </li>
          </ul>
    </div>
 </div>

I made a jsFiddle with my problem here: 我在这里用我的问题做了一个jsFiddle:

http://jsfiddle.net/rb6WJ/ http://jsfiddle.net/rb6WJ/

Hope someone can help. 希望有人能帮忙。

Thanks! 谢谢!

Add the following jQuery code to your fiddle: 将以下jQuery代码添加到您的小提琴中:

var fCH = $("#filtersContainer").height();
var tSH = $("#typeSelector").height();
$("#selectorList").height(Number(tSH) - Number(fCH) - 3);

You need to subtract also the margin-bottom of 3 pixels. 您还需要减去3个像素的空白边距。

Working demo: http://jsfiddle.net/VVxY7/ 工作演示: http : //jsfiddle.net/VVxY7/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM