In the below image, you can see the red close button is scrolling out of view (should always remain top right).
I thought no problem, I will fix it with position: fixed
… then it’s positioned relative to the body, ok how about position: sticky
, also did not work. Seems like only absolute position works within a dialog, so weird.
LOREM.innerText = "Lorem Ipsum my latin is not so great. ".repeat(400);
#DIALOG {
position: relative;
overflow-y: auto;
max-height: 80vh;
max-width: 80vw;
}
#CLOSE {
position: absolute;
top: 0;
right: 0;
width: 32px;
height: 32px;
background-color: red;
}
<dialog open id="DIALOG">
<button id="CLOSE">X</button>
<div id="LOREM"></div>
</dialog>
2
Answers
Sticky is working. See this
If you want to put one element on top of another why don’t you wrap the two element in a wrapper and use
position: relative
andposition: absolute
in child elements.Here is an example: