我有以下的div元素FirstDiv
與內嵌樣式設置:如何讓一個元素的「頂部」位置等於另一個+ 60px的位置?
<div class="FirstDiv" style="position:absolute;top:16%;height:50%; width:24%;</div>
當按下一個按鈕,我使用toggleClass
添加SecondDiv
到FirstDiv
,使頂部由20像素下移。以下是我嘗試使用CSS & JQuery組合的(不成功的)JQuery。 (我甚至不知道你是否可以合併CSS/jQuery的這種方式。)
<style type="text/javascript">
.`SecondDiv`{
top:($(".FirstDiv").position().top + '20px') !important;
}
</style>
我也代替.position()
試圖.offset().
但這並不工作。
jQuery是JavaScript的,而不是CSS。 –
@ThomasLandauer看看它的結構。它設置在'css'中。我會添加更多的細節來幫助你。 – Snoops
我在回答中添加了其他方法。 – Laurianti