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
1 Answer
Reset to default 4You 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;
}
版权声明:本文标题:html - How to position a popup beside the button that triggered it with css and javascript? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744767533a2624131.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论