我有一个iframe <iframe src="preloader.gif" id="graphFrame"...></iframe>。我想将图像放在iframe中。我已经尝试过在线查找解决方案,但是没有一个起作用。可以用简单的CSS完成吗?如果没有,还有其他解决方案吗?

最佳答案

不,您要提供的图片不是html页面,因此CSS不适用。


  它的作用就像一个预加载器
  图片,以便在实际内容加载时
  它将叠加在预加载器上
  图片


既然如此,我建议您:


通过设置使iframe的背景透明
allowTransparency="true"该属性名称在Internet Explorer iirc中区分大小写。
将以下样式应用于iframe:

background-image: url('preloader.gif');
background-position: center center; background-repeat: no-repeat;

src停在具有透明背景
html, body {
  background-color: transparent;
}
的html页面上


内容加载到iframe中后,它将覆盖正在加载的图片。 Working Example

关于css - 在iframe中居中放置图片,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5409124/

10-11 22:04
查看更多