将一个 DIV 放置在另一个 DIV 的底部

发布于 2024-10-06 11:10:03 字数 420 浏览 0 评论 0原文

我试图将一个 DIV 放置在另一个 DIV 的底部。

当我将外部 div 的高度设置为某个绝对高度(即 - 100px)时,它工作正常。当它设置为百分比或根本没有设置时 - 我无法定位它。

这是我的 CSS:

#left_pane 
{
    float: left;
    margin-left: 21px;
    position: relative;
}

#bottom_pic_wrapper
{
    position: absolute;
    bottom: 0;
}

#bottom_pic_wrapper 位于 #left_pane 内部,并且应与其底部对齐。

有什么想法为什么这对我不起作用吗?

谢谢 :)

I'm trying to position a DIV inside another DIV on its' bottom part.

When I set the outer divs' height to some absolute height (i.e - 100px), it works fine. When It's set to percents or isn't set at all - I can't position it.

Here is my CSS:

#left_pane 
{
    float: left;
    margin-left: 21px;
    position: relative;
}

#bottom_pic_wrapper
{
    position: absolute;
    bottom: 0;
}

the #bottom_pic_wrapper is inside of #left_pane and should be aligned to its' bottom.

Any ideas why this won't work for me?

Thanks :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

陌上芳菲 2024-10-13 11:10:03

我在 jsfiddle 中做了一个例子,看看它是否对你有用

http://jsfiddle.net/RJXez/

如果您需要任何其他信息,请告诉我

以下代码应该帮助您始终位于底部

var parentOffset = $('#div').offset();
   var parentsHeight= $('#div').height();
   var childsTopPostion= (parentOffset.top+parentsHeight) - heightOfchildDiv

   $('#childdiv').css('top',childsTopPostion);
   $('#childdiv').css('left',parentOffset.left);

I made one example here in jsfiddle , see if it useful to you

http://jsfiddle.net/RJXez/

let me know if you need anything else

The following code should help you position at the bottom always

var parentOffset = $('#div').offset();
   var parentsHeight= $('#div').height();
   var childsTopPostion= (parentOffset.top+parentsHeight) - heightOfchildDiv

   $('#childdiv').css('top',childsTopPostion);
   $('#childdiv').css('left',parentOffset.left);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文