簡體   English   中英

jQuery如何設置div相對於另一個div的位置?

[英]jQuery how to set the position of a div with relative to another div?

我的html中有兩個以下div,

<div id="chart-2" class="graph"></div>
<div id="chart2Buttons"></div>

第一個div代表我使用highchart.js繪制的圖形,第二個div代表我應該放置在第一個div下的按鈕,如下圖所示。 在此處輸入圖片說明

您能幫我如何實現將第二個div放置在第一個div的右下角嗎?

謝謝

添加CSS規則:

#chart2Buttons {
    display: inline-block;
    float: right;
}

試試這個CSS:

#chart-2{
  position:relative;
}

#chart2Buttons{
   position:absolute:
   bottom:1px;
   right:1px;
}

將包裝器div添加到圖表和按鈕,並將顯示設置為內聯塊和包裝器的相對位置。 絕對定位按鈕並將其放在下角,如下所示

 .graph{ width: 400px; height: 400px; background: crimson; line-height: 400px; text-align: center; color: white; font-size: 20px; } .wrapper{ position:relative; display: inline-block; } #chart2Buttons{ position: absolute; width: 40px; height: 40px; right: 0; bottom: 0; background: cornflowerblue; color: white; line-height: 40px; text-align: center; } 
 <div class="wrapper"> <div id="chart-2" class="graph"> GRAPH </div> <div id="chart2Buttons">B</div> </div> 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM