我有一个带有搜索字段,两个列表和文本div的边栏。搜索字段和文本div的高度总是相同,但两个列表的高度是未知的(意味着它们会改变)。基于其他div动态高度的动态div高度
我不知道是否有一些方法,只有CSS,使第一个div的高度动态变化,因此它根据浏览器窗口的高度和秒数列表中项目的高度/数量而变化。第二个列表可以有0到20个项目之间的任何地方,最大高度为整个页面高度的40%。
<style>
body, html {
height: 100 % ;margin: 0;padding: 0;
}
ul {
list - style: none;
margin: 0;
padding: 0;
}
#sidebar {
max - height: 100 % ;
overflow: hidden;
width: 300 px;
}
#inputContainer {
height: 50 px;
max - height: 50 px;
overflow: hidden;
background: #eee;
}
#firstList
{
background: #ddd
}
#secondList
{
width: 100 % ;
background: #bbb;
position: absolute;
bottom: 120 px;
width: 300 px;
}
#firstList ul
{
max - height: 230 px; /*THIS SHOULD NOT BE A STATIC NUMBER*/
overflow - y: scroll;
}
#secondList ul
{
overflow - y: scroll
max - height: 40 % ;
min - height: 200 px;
}
#otherBox
{
position: absolute;
bottom: 0 px;
background: #333;
color:# fff;
height: 100 px;
width: 300 px;
}
我创建了一个plunkr来演示我想要做什么。
恐怕我不能在这种情况下做到这一点。 inputContainer和otherBox的高度必须设置为固定的像素数。 – gusper 2014-12-02 09:58:52
@gusper好的给它(第二个div)一个自动高度,看看我的编辑。 – 2014-12-02 11:59:02