Given the following markup:
#containing-box {
margin: auto;
width: 300px;
height: 300px;
background: green;
transform: translate3d(0,0,0);
}
#fixed-box {
position: fixed;
top: 0;
left: 0;
width: 100px;
height: 100px;
background: red;
}
<div id="containing-box">
<div id="fixed-box"></div>
</div>
Is there a way to have the #fixed-box
be position relative to the viewport rather than the #containing-box
without changing the styles of the #containing-box
. I'm fine with adding any extra markup inside of the #containing-box
I just need to find a way to break out of the #containing-box
.
EDIT
I found an answer to my problem. Just swap out the div
with a dialog
element instead.
const dialog = document.querySelector('dialog');
dialog.showModal();
#containing-box {
margin: auto;
width: 300px;
height: 300px;
background: green;
transform: translate3d(0,0,0);
}
dialog {
position: fixed;
top: 0;
left: 0;
bottom: auto;
right: auto;
width: 100px;
height: 100px;
background: red;
}
<div id="containing-box">
<dialog></dialog>
</div>