加载页面和定位元素后 JQuery 中的绝对定位

发布于 2024-08-09 04:04:55 字数 121 浏览 2 评论 0原文

我想在普通CSS中相对于它之前的元素定位一个元素,然后一旦它被最初定位,就使其位置独立于它之前的元素。

例如,当您单击侧栏中的“小部件”时,它会折叠,并且其下方的所有“小部件”都会向上移动。我不想让他们动。谢谢。

I want to position an element in normal css relative to the element before it, and then once it's been initially positioned makes its position independant of the one before it.

For example, when you click on a 'widget' in the sidebar, it collapses, and all of the 'widgets' below it move up. I don't want them to move. Thanks.

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

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

发布评论

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

评论(1

上课铃就是安魂曲 2024-08-16 04:04:58

您无法使用纯 CSS 执行此操作,但可以使用 jQuery 执行此操作,如下所示:

var elem = $('something');
var pos = elem.position();
elem.css({ position: 'absolute', top: pos.top, left: pos.left });

在 Javascript 运行之前,元素不得具有 position:absolute

You cannot do this with pure CSS, but you can do it with jQuery, like this:

var elem = $('something');
var pos = elem.position();
elem.css({ position: 'absolute', top: pos.top, left: pos.left });

Until the Javascript runs, the element must not have position: absolute.

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