[英]Align div in the same offset top than another
My question is pretty simple. 我的问题非常简单。 I have
div1
that has a variable offset().top
depending on other elements of the page. 我有
div1
,它有一个变量offset().top
取决于页面的其他元素。 I want to insert an absolute
div next to it (basically with the same absolute top
) either with just css or with javascript too. 我想在它旁边插入一个
absolute
div(基本上使用相同的绝对top
),或者仅使用css或使用javascript。
HTML looks something like HTML看起来像
<div>
<div id="div2">stuff</div>
</div>
<div>
<div>some divs</div>
<div id="div1">div1 stuff </div>
</div>
因为在评论中你说你想在div2
插入DOM之后放置它,你可以尝试以下方法:
$('#div2').css('top', $('#div1').offset().top - $('#div2').offset().top)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.