离子框架:无法创建具有透明背景的iframe

发布于 2025-02-11 02:47:24 字数 806 浏览 0 评论 0原文

我目前正在尝试使用React创建一个网站,其中我需要在网站内有一个透明的iframe。我尝试了多种方式,所有方法都导致了白色背景。

这个问题似乎在某种程度上是离子框架起作用的,因为我在香草中尝试了相同的片段,并且是有意的。

我已经尝试了从设置允许Transparency =“ true” 到将iframe背景更改为透明的所有方法,但似乎不起作用。总是导致白色背景。

我尝试了这个小片段

html

 <div className="container">
     <iframe className='iframe' allowTransparency src="about:blank"></iframe>
 </div>

css:

.container {
  background-color: red;
  padding: 300px;
}

.iframe {
  background: transparent;
  background-color: transparent;
  width: 50vw;
  height: 50vh;
}

结果:

更新:更新:

该解决方案是为iframe使用与原始DOM相同的颜色安全。最好由Neea解释:

I am currently trying to create a website with Ionic Framework using React where I need to have a transparent iFrame inside the website. I have tried many ways and all result in a white background.

The issue seems to be in a way ionic Framework works because I have tried the same snippets in vanilla React and it worked as intentional.

I have tried everything from setting allowTransparency="true" to changing the IFrame background to transparent but it doesn't seem to work. Always resulting in a white background.

I tried with this small snippet

HTML

 <div className="container">
     <iframe className='iframe' allowTransparency src="about:blank"></iframe>
 </div>

CSS:

.container {
  background-color: red;
  padding: 300px;
}

.iframe {
  background: transparent;
  background-color: transparent;
  width: 50vw;
  height: 50vh;
}

Results:

  1. In case of Vanilla (normal) React the background is transparent and only border of the iframe is visible

  2. In case of Ionic Framework with React the background remains white

Update:

The solution is to use the same color-scheme for the iframe as the original DOM. Best explained by Neea here https://stackoverflow.com/a/69671458/14341569

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文