简体   繁体   English

jQuery如何设置div相对于另一个div的位置?

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

I am having below two divs inmy html, 我的html中有两个以下div,

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

First div represents the graph which I am plotting using highchart.js while second represents the buttons which I am supposed to place under first div as show in below image. 第一个div代表我使用highchart.js绘制的图形,第二个div代表我应该放置在第一个div下的按钮,如下图所示。 在此处输入图片说明

Can you please help how can I achieve this to place my second div at the bottom-right corner of first div? 您能帮我如何实现将第二个div放置在第一个div的右下角吗?

Thanks 谢谢

Add css rule: 添加CSS规则:

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

Try this CSS: 试试这个CSS:

#chart-2{
  position:relative;
}

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

Add a wrapper div to the chart and button and set the display to inline-block and position relative for the wrapper. 将包装器div添加到图表和按钮,并将显示设置为内联块和包装器的相对位置。 Position absolute the button and place it at bottom corner as below 绝对定位按钮并将其放在下角,如下所示

 .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