相对于非父div的位置div - 这可能吗? [英] Position div relative to non-parent div - is this possible?

查看:75
本文介绍了相对于非父div的位置div - 这可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以相对于另一个 div 定位 div 哪个不是它的父亲?例如:

Is it possible to position a div relative to another div which is not it's parent? For example:

<div id="header"><!-- --></div>
<div id="content"><!-- --></div>
<div id="footer"><<!-- --></div>

在上面的代码中,可以 #footer 相对定位于 #header

In the above code, could #footer be relatively positioned to #header?

更新

我问,因为我打算实现的设计的语义结构与我想呈现它的方式不符。在视觉上我会在页面顶部有一个菜单和一个隐藏的div,它将在点击事件的菜单上方滑动。因此,我需要对订单或div进行随机播放,以使 #menu 相对位于 #header 以下并保留当 #header 在jQuery slideToggle()事件中滑入时相对定位。

I ask because the semantic structure of the design I intend to implement doesn't match the way I want to present it. Visually I'll have a menu at the top of the page and a hidden div which will slide in above the menu on a click event. I therefore need to shuffle the order or divs such that a #menu is relatively positioned below a #header and will stay relatively positioned when the #header slides in on a jQuery slideToggle() event.

<div id="menu"><!-- --></div>
<div id="header"><!-- --></div>
<div id="content"><!-- --></div>
<div id="footer"><<!-- --></div>

#header 应固定在顶部的窗口。 #menu 应相对于 #header 定位,以便当 #header 幻灯片, #menu 向下滑动相同距离。

#header should be fixed to the top of the window. #menu should be positioned relative to #header such that when #header slides in, #menu slides down by the same distance.

推荐答案

如何在jQuery中移动HTML元素?

这个问题提供了我需要的答案。基本上你可以使用jQuery在页面加载时移动DOM中的元素;请注意,在尝试操作DOM之前允许页面首先加载是很重要的。

This question provided the answer I required. Basically you can use jQuery to move the element in the DOM on page load; note it's important to allow the page to load first before attempting to manipulate the DOM.

这篇关于相对于非父div的位置div - 这可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆