HTML - 隐藏iframe

use*_*743 19 html iframe

如何隐藏iframe,但仍然加载它?等等.播放youtube歌曲.

<iframe src="https://www.youtube.com/embed/X18mUlDddCc?autoplay=1" style="display: none;"></iframe>
Run Code Online (Sandbox Code Playgroud)

这将隐藏iframe,但它似乎不会加载iframe.(宋没有上演.)

谢谢

YOU*_*YOU 16

使用可以使用宽度0,高度0和边框0

所以更新的代码将是!

<iframe src="https://www.youtube.com/embed/X18mUlDddCc?autoplay=1" style="width:0;height:0;border:0; border:none;"></iframe>
Run Code Online (Sandbox Code Playgroud)

添加:

style="width:0; height:0; border:0; border:none"

它将隐藏它,使媒体在后台播放,它也会崩溃它的空间!

更新小提琴

http://jsfiddle.net/0g51po9t/1/

  • 如果我编辑小提琴以在其上方和下方添加元素,我可以看到此 iframe 占用空间。 (2认同)

Dan*_*But 9

在我添加绝对定位之前,我仍然遇到iframe占用空间的问题.然后它一起停止占用空间.

<iframe src="/auth/sso/" style="width: 0; height: 0; border: 0; border: none; position: absolute;"></iframe>


Sha*_*ane 6

使用 CSS 的现有答案对我不起作用。即使display:none我最终在 iframe 所在的位置得到了一个 4x4 点。我必须做的是以下内容:

<iframe width="0" height="0" frameborder="0" src="https://www.youtube.com/embed/X18mUlDddCc?autoplay=1"></iframe> 
Run Code Online (Sandbox Code Playgroud)


Fue*_*fee 5

将可见性设置为隐藏。但是,占用的空间不会崩溃。

<iframe src="https://www.youtube.com/embed/X18mUlDddCc?autoplay=1" style="visibility: hidden;"></iframe>
Run Code Online (Sandbox Code Playgroud)