透明背景iframe仅在Firefox而不是Chrome或Safari工作

发布于 2025-01-17 15:11:45 字数 839 浏览 3 评论 0 原文

我试图在 iframe 上获得透明背景,但我只能在 Firefox 上使用它。我已经尝试了所有不同的方法让它工作,但这是我现在在 iframe 中的页面上使用的 css:

html, body {
    background: linear-gradient(top, blue, transparent);
}
这是 Firefox 中的结果(以及所需的结果): 这就是我进入 Safari 的 chrome:

我使用 JavaScript 添加的 iframe:

<iframe class='repoImg' allowtransparency='true' frameborder='0' src='objectpreview.html?objecturl="+ element +"' title='3D model of "+ element +"'>

有没有办法在所有浏览器上获得所需的结果?

I'm trying to get a transparent background on an iframe, but I only am able to get it working on firefox. I have tried all the different ways of getting it to work, but this is the css that I'm using now on the page that is in the iframe:

html, body {
    background: linear-gradient(top, blue, transparent);
}
This is the result in Firefox(and the desired result): And this is what I get in chrome of safari:

The iframe that I add using JavaScript:

<iframe class='repoImg' allowtransparency='true' frameborder='0' src='objectpreview.html?objecturl="+ element +"' title='3D model of "+ element +"'>

Is there a way to get the desired result across all browsers?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

忱杏 2025-01-24 15:11:45

iframes默认为透明

html, body {
    background: linear-gradient(#e66465, #9198e5);
    height: 100%;
}
<iframe src="data:text/html,<DOCTYPE html><h1>This is an iframe</h1>"></iframe>

如果iframe自己设置了背景颜色,则它将使用其选择的任何颜色。但是,如果它没有设置背景颜色,则它是透明的,并显示到父母的页面。

由于您得到的结果不同,因此iframe中的某些内容正在制作白色。

iframes default to transparent

html, body {
    background: linear-gradient(#e66465, #9198e5);
    height: 100%;
}
<iframe src="data:text/html,<DOCTYPE html><h1>This is an iframe</h1>"></iframe>

If the iframe is setting a background color on it's own then it will use whatever color it chose. But if it does not set a background color then it's transparent and shows through to the parent's page.

Since you're getting a different result, something in your iframe is making that white color.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文