How can I position my modal relative to a parent element in my component?
See original GitHub issueSummary:
Steps to reproduce:
- Set app element to the app root:
ReactModal.setAppElement('#root');
- Create a basic modal with props like these:
</nav>
<ReactModal
isOpen={state.delete}
onRequestClose={ () => { setState(prevState => ({ delete: !prevState.delete })) } }
shouldCloseOnOverlayClick={true}
className="h-auto m-auto card px-5 py-4"
style={{
overlay: {
'background': 'rgba(138, 145, 153, .66)'
},
content: {
'width': '400px',
'marginTop': '25vh',
}
}}
>
- Modal is positioned like a fixed element in the center of the viewport.
What I want
I want to position this modal relative to it’s parent component. This modal is for a user menu popup, and it needs to appear below a fixed navbar. The position of the user image is not static. The site is responsive, so the dropdown must be relative to that parent.
Link to example of issue:
https://www.google.com has a similar modal popup when you sign in with an account.
Here is an example image: https://imgur.com/KIykuAc
Any help would be apprecieted.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:14
Top Results From Across the Web
How to position a modal relative to a layout when it's rendered ...
Just put position: absolute to the modal and for the parent, put a position: relative (for all parent like <Left> , <Right> etc)....
Read more >How to Set Absolute Positioning Relative to the Parent Element
Solution with the CSS position property. It is possible to set absolute positioning of a child element relative to the parent container.
Read more >Creating a modal inside a relative parent
When i write a modal code inside an element with position relative the modal backdrop is appended to the body and the modal...
Read more >How to Position a Div Element Over and Relative to Another
Nonetheless, we can set the height and width from CSS. ... The parent is set to relative position and the dialog has absolute...
Read more >Position an element relatively to another element from ... - WICG
``1. Make the dialog a sibling/ancestor: As long as the dialog and target element are related, I can position: relative; a common parent...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I have it set to my root. I’ll experiment with attaching it to the navigation bar by ID
Have you tried using parentSelector property from the docs?