admin管理员组

文章数量:1391811

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;
 } 

本文标签: htmlHow to position a popup beside the button that triggered it with css and javascriptStack Overflow