如何让div顶部成为其他div的底部

时间:2022-08-25 00:09:59

How do I make a div top to be the bottom of other div like this:

如何使div顶部成为其他div的底部,如下所示:

如何让div顶部成为其他div的底部

I selected with firebug the div that I need the top to be always the bottom of

我用firebug选择了div,我需要顶部始终是底部

<div class="menu-banner">

What CSS would do the trick, or I need to use jQuery for this?

什么CSS可以做到这一点,或者我需要使用jQuery?

The target div and teh menu-banner div are both direct child of body. And that target is not child of menu-banner.

目标div和teh菜单横幅div都是身体的直接子。而且该目标不是菜单横幅的子项。

4 个解决方案

#1


0  

position: absolute is breaking it for you. Your requested alignment is default for position: relative.

位置:绝对是为你打破它。您请求的对齐方式是position:relative的默认值。

#2


0  

You certainly don't need jQuery for this, you can solve this purely in CSS. The uppermost banner, the navigation bar and the image should all be relative to a parent container (it can just be the body element or you can have a container div).

你当然不需要jQuery,你可以纯粹用CSS解决这个问题。最上面的横幅,导航栏和图像都应该相对于父容器(它可以只是body元素,或者你可以有一个容器div)。

I know this is not exactly what you are asking, but you might consider using a framework such as bootstrap or foundation in order to help you with common layouts like the one you seem to be using.

我知道这不是你要求的,但你可能会考虑使用bootstrap或foundation这样的框架来帮助你使用像你似乎使用的那样的常见布局。

#3


0  

I can't understand you correctly, you may want to put a child box in the bottom of its parent, if so:
You can consider position: relative to the parent box and position: absolute and bottom: 0 to the child.

我无法正确理解你,你可能想在其父母的底部放一个子框,如果是这样的话:你可以考虑位置:相对于父框和位置:绝对和底部:0到孩子。

Check this JSFiddle

检查这个JSFiddle

#4


0  

I solved this problem by simply adding a padding-top with value 15%

我通过简单地添加一个值为15%的填充顶部解决了这个问题

#1


0  

position: absolute is breaking it for you. Your requested alignment is default for position: relative.

位置:绝对是为你打破它。您请求的对齐方式是position:relative的默认值。

#2


0  

You certainly don't need jQuery for this, you can solve this purely in CSS. The uppermost banner, the navigation bar and the image should all be relative to a parent container (it can just be the body element or you can have a container div).

你当然不需要jQuery,你可以纯粹用CSS解决这个问题。最上面的横幅,导航栏和图像都应该相对于父容器(它可以只是body元素,或者你可以有一个容器div)。

I know this is not exactly what you are asking, but you might consider using a framework such as bootstrap or foundation in order to help you with common layouts like the one you seem to be using.

我知道这不是你要求的,但你可能会考虑使用bootstrap或foundation这样的框架来帮助你使用像你似乎使用的那样的常见布局。

#3


0  

I can't understand you correctly, you may want to put a child box in the bottom of its parent, if so:
You can consider position: relative to the parent box and position: absolute and bottom: 0 to the child.

我无法正确理解你,你可能想在其父母的底部放一个子框,如果是这样的话:你可以考虑位置:相对于父框和位置:绝对和底部:0到孩子。

Check this JSFiddle

检查这个JSFiddle

#4


0  

I solved this problem by simply adding a padding-top with value 15%

我通过简单地添加一个值为15%的填充顶部解决了这个问题