This code doesn't have that issue. Does it solve your problem?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Demo</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
dialog {
position: relative;
border: 1px solid black; /* Default is 2px. */
}
dialog::backdrop {
background-color: salmon;
}
#closeButton {
font-size: 1.5em;
line-height: .75em;
position: absolute;
right: 0;
top: 0;
border-left: 1px solid black;
border-bottom: 1px solid black;
padding: 3px;
}
#closeButton:hover {
cursor: pointer;
background-color: black;
color: white;
}
</style>
</head>
<body>
<dialog>
<div id="closeButton" onclick="this.parentNode.close()">×</div>
<p>This is a dialog box.</p>
</dialog>
<script>
document.getElementsByTagName('dialog')[0].showModal(); // Or show() for a non-modal display.
</script>
</body>
</html>