I am encountering an issue with my iframe border when using CSS. The problem arises in Chrome where the border disappears upon resizing the page, while Safari changes the size (Firefox appears unaffected)
https://i.sstatic.net/ZUi9z.gif
Are there any known workarounds to fix this?
const code = `
<style>
body {
background: #DDD;
}
</style>
<body>
<div>hello iframe</div>
</body>
`;
const blob = new Blob([code], {type: 'text/html'});
document.querySelector("iframe").src = URL.createObjectURL(blob);
div {
max-width: 90%;
margin: 0 auto;
}
iframe {
display: block;
border: 1px solid black;
width: 100%;
background: red;
}
<p>Resize the window and observe the right border</p>
<!-- src set from JavaScript because offsite iframes are often banned -->
<div>
<iframe></iframe>
</div>
The issue does not occur when using other elements
div {
max-width: 90%;
margin: 1em auto;
}
span, canvas {
display: block;
border: 1px solid black;
width: 100%;
height: 60px;
background: #eee;
}
<p>No problems observed with other elements</p>
<div>
<span></span>
</div>
<div>
<canvas></canvas>
</div>
It seems that having a background color in the iframe is causing the issue. Removing the background color resolves the problem in Chrome but not in Safari
const code = `
<body>
<div>hello iframe</div>
</body>
`;
const blob = new Blob([code], {type: 'text/html'});
document.querySelector("iframe").src = URL.createObjectURL(blob);
div {
max-width: 90%;
margin: 0 auto;
}
iframe {
display: block;
border: 1px solid black;
width: 100%;
}
<p>Resize the window and watch the right border</p>
<!-- src set from JavaScript because offsite iframes are often banned -->
<div>
<iframe></iframe>
</div>