隐藏的嵌入src仍然占用空间



我有以下嵌入代码:

<embed src="audio/tileSelect.wav" autostart="false" width="1" height="1" hidden="true" id="sound1" enablejavascript="true">
<embed src="audio/tileRemove.wav" autostart="false" width="1" height="1" hidden="true" id="sound2" enablejavascript="true">

尽管这些都是隐藏的(我没有看到),但它们仍然占据了空间。如何移除他们使用的额外空间?

我试着用display: none;把它放在div中,但这让我的音频无法工作。

有什么建议吗?

感谢

接受的答案对我不起作用,使用IE7-9时屏幕上仍有空白。我知道这是一个老帖子,自从给出这个答案以来,浏览器已经改变了。将下面的代码保存为audio.html,并在IE7-10和最新版本的Chrome、Safari和FireFox中运行。您将看到,使用已接受答案中的样式仍然会在屏幕上显示与IE7-9的差距。我使用的方法没有。

此外,我在可用时使用HTML5 <audio>标记,然后在需要时返回到<embed>标记3schools目前推荐的,我已经测试了所有主要的浏览器和版本,所以截至2014年5月13日,它似乎对我很有效。

希望这能有所帮助。

(音频可能需要一秒钟才能开始播放,它来自archive.org)

<div style="background-color:lightgray; height:100px; width:300px; padding:5px;">
    This is the solution I am using so that the embed tag doesn't take up any room...<br>
    Audio is embedded below this block.  You will see no gap in any browser.
</div>
<div style="position:absolute; top:0px; left:0px;">
    <audio autoplay>
        <source src="https://archive.org/download/testmp3testfile/mpthreetest.mp3" type="audio/mpeg">
        <embed width="1" height="1" hidden="true" src="https://archive.org/download/testmp3testfile/mpthreetest.mp3">
    </audio>
</div>
<div style="background-color:gray; height:20px; width:300px; padding:5px;">
    Audio is embedded above this block
</div>
<div style="background-color:aqua; height:100px; width:300px; padding:5px; margin-top:30px;">
    Using a div with "position: relative; top: -50px; left: -50px; overflow: hidden;" still gives a gap...<br>
    Audio is embedded below this block.  You will see a gap in IE7-9.
</div>
<div style="position: relative; top: -50px; left: -50px; overflow: hidden;">
    <audio autoplay>
        <source src="https://archive.org/download/testmp3testfile/mpthreetest.mp3" type="audio/mpeg">
        <embed width="1" height="1" hidden="true" src="https://archive.org/download/testmp3testfile/mpthreetest.mp3">
    </audio>
</div>
<div style="background-color:green; height:20px; width:300px; padding:5px;">
    Audio is embedded above this block
</div>

嗯得到了一个解决方案(虽然不是很漂亮):

.au {
    position: relative; 
    top: -50px; 
    left: -50px; 
    overflow: hidden;
}

把它放在一个div中,并给它这些比例

最新更新