Mac*_*iej 3 html javascript css layout
看一下这个例子:http: //jsbin.com/ixiju4/2/edit
我有一个包装器,其高度被定义,内部有两个容器:顶部和底部.顶部容器的高度不固定(在示例中它设置为100px,但这仅用于演示).我想要的是动态设置底部容器以填充包装器的其余部分.
在这个演示中,我使用JS做到了:
$(function() {
var top = $('#top');
var bottom = $('#bottom');
bottom.height(bottom.parent().height()-top.outerHeight());
});
Run Code Online (Sandbox Code Playgroud)
你认为在纯HTML/CSS中有办法吗?无论如何,我甚至可以使用表格.我一直在考虑解决方案一段时间,并没有发现任何跨浏览器兼容的解决方案.谢谢你的帮助.
更新1: 我犯了一个错误,定义了这个问题top没有固定的高度 - 它是由它的内容定义的. http://jsbin.com/ixiju4/6
更新2: 好的.这就是我真正想要的:http: //jsbin.com/ixiju4/8
有一个非常简单的纯CSS解决方案:
#wrapper {
position: absolute;
width: 100%;
height: 100%;
}
#top {
height: 100px;
width: 100%;
background-color: #00f4f7;
}
#bottom {
background-color: #00f400;
width: 100%;
height: 100%
}
Run Code Online (Sandbox Code Playgroud)
更新2继续上一轮编辑之后,我相应地更新了CSS,即:
#wrapper {
position: absolute;
width: 100%;
height: 100%;
overflow: hidden;
}
#top {
background-color: #00f4f7;
}
#bottom {
background-color: #00f400;
height: 100%;
padding: 10px;
}
#inner {
height: 100%;
background-color: #f0f400;
margin-bottom: 10px;
}
Run Code Online (Sandbox Code Playgroud)