如何将内部div与外部div的底部对齐?

我需要将内部div与外部div的底部对齐。

我的代码如下所示:

Variable content here

‘div1’的内容可能会有所不同,因此外部div的高度会发生变化。 如何确保我的按钮(div2)始终位于外部div的底部?

我更喜欢使用CSS,但如果不可能,我可以使用jQuery。

UPDATE

我选择以jQuery方式执行此操作,在此我碰到了一些问题。 这一切都解决了,你可以在这里找到我的工作解决方案: 如何使用jQuery计算元素跨浏览器的高度?

试试这个:

 .myOuterDiv { position: relative; } .div2 { position: absolute; bottom: 0 } 

使某个位置绝对会将其从流中移除 ; 您可以通过向.myOuterDiv添加底部填充来解释这一点,该填充等效于.div2的高度

Mike的解决方案适用于所有浏览器。 这是我的代码使用他的想法做你想要的:

       
Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32. The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.

我会帮忙,但我在移动。 但这只是使用jquery的提示。

获取两个div的高度值。 相互减去高度值。 现在使用结果的值来控制右边div的margin-top以将其向下推。

如果我在我的桌子或笔记本电脑上,我会回来看看。

您的评论暗示您将只在div拥有图像而不是其他任何内容。 在这种情况下,您可以将其设置为背景图像,与底部对齐:

  
Variable content here

如果您需要,可以使用left bottomcenter bottom而不是center bottom 。 你可能也不需要内部div