离子框架:无法创建具有透明背景的iframe
我目前正在尝试使用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:
In case of Vanilla (normal) React the background is transparent and only border of the iframe is visible
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论