[英]How to create dynamic horizontal layout in pure HTML/CSS no JS?
Take a look at this example: http://jsbin.com/ixiju4/2/edit 看一下这个例子: http : //jsbin.com/ixiju4/2/edit
I have a wrapper which height is defined and two containers inside: top and bottom . 我有一个包装器 ,其高度被定义,内部有两个容器: 顶部和底部 。 The height of the top container isn't fixed (in the example it is set to 100px but this is just for demonstration).
顶部容器的高度不固定(在示例中它设置为100px,但这仅用于演示)。 What I want is to dynamically set the bottom container to fill the rest of the wrapper.
我想要的是动态设置底部容器以填充包装器的其余部分。
In this demonstration I did it using JS: 在这个演示中,我使用JS做到了:
$(function() {
var top = $('#top');
var bottom = $('#bottom');
bottom.height(bottom.parent().height()-top.outerHeight());
});
Do you think there is a way to do it in pure HTML/CSS? 你认为在纯HTML / CSS中有办法吗? No matter how, I can even use tables .
无论如何,我甚至可以使用表格 。 I've been thinking about the solution for some time now and haven't found any cross browser compatible one.
我一直在考虑解决方案一段时间,并没有发现任何跨浏览器兼容的解决方案。 Thanks for any help.
谢谢你的帮助。
UPDATE 1: I've made one mistake defining this questions top has no fixed height - it is defined by it's content. 更新1:我犯了一个错误,定义了这个问题top没有固定的高度 - 它是由它的内容定义的。 http://jsbin.com/ixiju4/6
http://jsbin.com/ixiju4/6
UPDATE 2: OK. 更新2:好的。 This is what I really want: http://jsbin.com/ixiju4/8
这就是我真正想要的: http : //jsbin.com/ixiju4/8
There's a pretty easy pure CSS solution to this: 有一个非常简单的纯CSS解决方案:
#wrapper {
position: absolute;
width: 100%;
height: 100%;
}
#top {
height: 100px;
width: 100%;
background-color: #00f4f7;
}
#bottom {
background-color: #00f400;
width: 100%;
height: 100%
}
UPDATE 2 Following on from your last round of editing to the question, I've updated the CSS accordingly, which is: 更新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;
}
Well, if you can use tables: 好吧,如果你可以使用表格:
<table style="height:400px">
<tr>
<td style="height:100px">Fixed to arbitrary value</td>
</tr>
<tr>
<td style="height:auto">Dynamically filling</td>
</tr>
</table>
http://jsbin.com/ixiju4/3 http://jsbin.com/ixiju4/3
Disclaimer: Dear Googler, if you found this answer: Don't do this at home! 免责声明:亲爱的Google员工,如果您找到了答案:不要在家里这样做! Tables for styling are evil.
造型表是邪恶的。 Use
display: table
and display: table-row
to achieve the same effect in everything but IE < 8 使用
display: table
和display: table-row
在除IE <8之外的所有内容中实现相同的效果
Edit 2: OK, for completeness: 编辑2:好的,为了完整性:
#wrapper { display: table; }
#top, #bottom { display: table-row; }
Doesn't work in IE < 8, as mentioned. 如上所述,在IE <8中不起作用。 http://jsbin.com/ixiju4/5
http://jsbin.com/ixiju4/5
Edit 3: I was really blind. 编辑3:我真的失明了。 Yes, Tiny Giant Studios answered with the obvious way to do it.
是的,Tiny Giant Studios以明显的方式回答了这个问题。 You should go with his answer.
你应该回答他的问题。 (I'm leaving mine for completeness.)
(我要完全离开我了。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.