从下到上垂直展开DIV
我想从下到上垂直扩展 DIV,而不使用百分比或函数(仅 css)。我有两个 div,但只有第二个具有定义的高度,因此我必须用第一个 div 修复其余空间。
这是我的代码:
<html>
<head>
<style>
#one { position: absolute; width: 100%; background: red; top: 0 }
#two { position: absolute; width: 100%; background: yellow; bottom: 0; height: 200 }
</style>
</head>
<body>
<div id="one">"DIV 1" has to be stucked to "DIV 2"</div>
<div id="two">I wanna "DIV 2" determines the height of "DIV 1"</div>
</body>
</html>
问题是红色 div 停留在顶部 :S
任何帮助将不胜感激,感谢您的时间! 友好,Chumpocomon
I would like to expand a DIV vertically from the bottom to the top without using percents or functions (only css). I have two div but only the second one has a defined height, so I have to fix the rest of the space with my first div.
Here is my code:
<html>
<head>
<style>
#one { position: absolute; width: 100%; background: red; top: 0 }
#two { position: absolute; width: 100%; background: yellow; bottom: 0; height: 200 }
</style>
</head>
<body>
<div id="one">"DIV 1" has to be stucked to "DIV 2"</div>
<div id="two">I wanna "DIV 2" determines the height of "DIV 1"</div>
</body>
</html>
You can put the code here to see what I'm getting
The problem is that the red div stay on the top :S
Any help will be appreciated, thanks for your time!
Friendly, Chumpocomon
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
如果我正确理解你的问题,这应该是你所追求的:
http://jsfiddle.net/ peduarte/RnKmE/1/
*编辑*
我不确定你是否可以用 CSS 来做到这一点。
不过,我在 jQuery 中做了一个例子。
http://jsfiddle.net/peduarte/RnKmE/3/
If I understood your questions correctly, this should be what you're after:
http://jsfiddle.net/peduarte/RnKmE/1/
*EDIT*
I am not sure if you can do it with CSS.
However, I did an example in in jQuery.
http://jsfiddle.net/peduarte/RnKmE/3/
在纯 CSS 中执行此操作的方法是仅在示例中添加一行代码:
就完成了:)
示例
The way to do this in pure CSS is to add only one line of code to your example:
and you're done :)
Example
像这样写:
http://jsfiddle.net/sj2AD/7/
Write like this:
http://jsfiddle.net/sj2AD/7/
演示
Demo
看看这个,我想这就是您要找的:
jsfiddle.net/mcverde/XZ253/
该脚本仅用于动态添加内容。
check this out, I think it is what you´re looking for:
jsfiddle.net/mcverde/XZ253/
The script is only to add content on the fly.
我意识到这是一个超级老问题,你一定很久以前就找到了答案,但我刚刚找到它并使用 Flex 尝试了一下。您所需要做的就是让一个容器 div 显示在 Flex 中。
https://jsfiddle.net/bksLtm06/
I realize this is a SUPER old question and you must have found an answer ages ago, but I just found it and took a stab at it using Flex. All you need to do is have a container div displaying in flex.
https://jsfiddle.net/bksLtm06/