If you use React then you can use ReactDOM.createPortal.
Credit goes for Porkopek for the tip, but it took me some time to figure out what this thing is.
So here's what I found:
If you return a component wrapped in ReactDOM.createPortal then as the second argument you can set the parent element, and React will append the component to that given element, so example position: fixed
will be fine even as a child of a transformed component.
import ReactDOM from "react-dom";
const MyModal = () => {
return ReactDOM.createPortal(
<div style={{position: "fixed", top: "0", left: "0",
background: "white", color: "black",
padding: "3rem", zIndex: "50000"}}>
Modal Element
</div>,
document.body
)
}
In this case React will render this component as the child of the body, not as the child of the parent component.