我試圖在窗口中居中的另一塊(綠色塊)的右上方放置一個塊(紅色塊)。
綠色塊是一張圖片。
我怎麼能做到這一點? 動態地改變塊的位置,將位置定位在居中塊上
#flag {position: absolute; background-color: green; height:6vw; width:15vw; color: white; text-align:center; }
#introduction {display: table; margin-left: 20%; margin-right: 20%; width: 60%; height: 100vh;}
#caser img {width: 100%; height: auto;}
#caser {padding-top:6vw; padding-bottom:6vw; display: table-cell; height: 100%; vertical-align: middle;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="flag">
<a class="linkme" id="go" target="_blank" href="https://www.google.fr/?gws_rd=ssl">
Hello
</a>
</div>
<div id="introduction">
<div id="caser"><a href="http://www.google.fr">
<img src="http://bhrabbitrescue.org/wp-content/uploads/2011/02/cute-bunnies-tongues-6.jpg">
</a>
</div>
</div>
我發佈了我的第一個想法......但終於不是很好。你應該尋找一個腳本來找到圖像在頁面中的確切位置,以計算給你的綠色塊的位置。尋找[jQuery偏移量](http://www.w3schools.com/jquery/css_offset.asp) –