html - How to position a popup beside the button that triggered it with css and javascript? - Stack Overflow

I am currently dynamically creating x number of divs and within each div, I have a button that shows a

I am currently dynamically creating x number of divs and within each div, I have a button that shows a popup whenever clicked.

I am trying to position the button below the specific button that triggered it but the position of the popup is always static for a reason, it does not move below the button.

<div className="popWrap">
    <div className="popup" id="pop" style={{display: 'none'}}>
            <Card className="myCardStyle"> 
               <CardHeader>hello</CardHeader>
               <CardBody>body</CardBody>
            </Card>
    </div>  
    <button className="myBtn" onClick={this.displayBtn}>View Button Info</button>
</div>

Here is my css:

.myCardStyle {
width: 100%;
 }

.popup {
   z-index: 10000;
 }

.popwrap{
   border:1px solid pink;
   padding:1px;
   position: inherit;
   display:inline-block;
 } 

Anyone can suggest a solution? Thanks in advance!

I am currently dynamically creating x number of divs and within each div, I have a button that shows a popup whenever clicked.

I am trying to position the button below the specific button that triggered it but the position of the popup is always static for a reason, it does not move below the button.

<div className="popWrap">
    <div className="popup" id="pop" style={{display: 'none'}}>
            <Card className="myCardStyle"> 
               <CardHeader>hello</CardHeader>
               <CardBody>body</CardBody>
            </Card>
    </div>  
    <button className="myBtn" onClick={this.displayBtn}>View Button Info</button>
</div>

Here is my css:

.myCardStyle {
width: 100%;
 }

.popup {
   z-index: 10000;
 }

.popwrap{
   border:1px solid pink;
   padding:1px;
   position: inherit;
   display:inline-block;
 } 

Anyone can suggest a solution? Thanks in advance!

Share Improve this question asked Jun 15, 2021 at 8:49 purplewindpurplewind 3611 gold badge11 silver badges26 bronze badges 2
  • Please create a proper minimal reproducible example. – user5734311 Commented Jun 15, 2021 at 8:51
  • Duplicate: Position one element relative to another in CSS – user5734311 Commented Jun 15, 2021 at 9:32
Add a ment  | 

1 Answer 1

Reset to default 4

You could add position: relative; to the .popWrap div. Then you can set position: absolute; to the .popup element and give it a specific (top) position to move it where you want it to be.

Example:

.popup {
   position: absolute;
   top: 50px;
   z-index: 10000;
 }

.popWrap {
   position: relative;
   border: 1px solid pink;
   padding: 1px;
   display: inline-block;
 } 

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744767533a4592551.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信