HTML:iframe 元素之间有奇怪的空间?

发布于 2024-12-02 12:21:07 字数 3138 浏览 1 评论 0原文

问题:

考虑以下 HTML:

<html>
<head></head>

<body>

<div style="float:left;">
  <div style="background-color: Red; padding-top: 2mm; padding-bottom: 2mm;">
        Dock: Usage controls/symbol list here
    </div>


    <div style="height: 300px; background-color: Khaki; display:block; float:left; overflow: scroll;">

        <ul style="background-color: White; float: left; margin: 0px; padding: 0px; padding-left: 30px; padding-right: 10px;">
            <li>
                <a href="Folders/Content/Inbox" target="ifrmFolderContent" >
                    Posteingang / Inbox
                </a>
            </li>
            <li>
                <a href="Folders/Content/Drafts" target="ifrmFolderContent" >
                    Entwürfe / Drafts
                </a>
            </li>
            <li>
                <a href="Folders/Content/Sent Items" target="ifrmFolderContent" >
                    Gesendet / Sent Items
                </a>
            </li>
            <li>
                Archiv / Archive
            </li>
            <li>
                Papierkorb / Trash
            </li>
            <li>
                Junk / Crap
            </li>
            <li>
                Scam
            </li>
            <li>
                Spam
            </li>
            <li>
                Virus
            </li>
            <li>
                Abrufen / Send & Receive
            </li>
            <li>
                Verfassen / Compose
            </li>
            <li>
                Adressbuch / Address book
            </li>
        </ul>
    </div>




    <div style="width: 400px; height: 300px; background-color: Green; display:block; float:left; margin: 0px; padding: 0px;">



       <iframe marginwidth="0" marginheight="0" hspace="0" vspace="0"  name="ifrmFolderContent" src="http://www.yahoo.com" frameborder="0" style="overflow: none; width: 400px; height: 150px; background-color: Orange; margin: 0px; padding: 0px;">

         Folder Content
       </iframe>



       <iframe marginwidth="0" marginheight="0" hspace="0" vspace="0"  name="ifrmEmail" src="http://www.msn.com" frameborder="0" style="overflow: none; width: 400px; height: 150px; background-color: Orange; margin: 0px; padding: 0px;">

         E-Mail Content

       </iframe>



    </div>



    <div style="background-color: Indigo; padding-top: 2mm; padding-bottom: 2mm; clear: left;">
        Copyright here
    </div>

</div>



</body>

</html>

它的呈现完全符合人们的预期 (Chrome + IE8)。

但现在,我补充说:

<!DOCTYPE html>

除此之外。

突然间,在 Chrome 和 IE8(尚未测试 FireFox)中,两个 iframe(文件夹内容/电子邮件内容)之间出现了 2 到 5 毫米的绿色空间。 更令人不安的是,似乎没有办法摆脱这个空间(除了删除

为什么?我的意思是,绿色来自 背景-color 的父元素,但是为什么两个 iframe 之间有一些空格?

Question:

Consider the following HTML:

<html>
<head></head>

<body>

<div style="float:left;">
  <div style="background-color: Red; padding-top: 2mm; padding-bottom: 2mm;">
        Dock: Usage controls/symbol list here
    </div>


    <div style="height: 300px; background-color: Khaki; display:block; float:left; overflow: scroll;">

        <ul style="background-color: White; float: left; margin: 0px; padding: 0px; padding-left: 30px; padding-right: 10px;">
            <li>
                <a href="Folders/Content/Inbox" target="ifrmFolderContent" >
                    Posteingang / Inbox
                </a>
            </li>
            <li>
                <a href="Folders/Content/Drafts" target="ifrmFolderContent" >
                    Entwürfe / Drafts
                </a>
            </li>
            <li>
                <a href="Folders/Content/Sent Items" target="ifrmFolderContent" >
                    Gesendet / Sent Items
                </a>
            </li>
            <li>
                Archiv / Archive
            </li>
            <li>
                Papierkorb / Trash
            </li>
            <li>
                Junk / Crap
            </li>
            <li>
                Scam
            </li>
            <li>
                Spam
            </li>
            <li>
                Virus
            </li>
            <li>
                Abrufen / Send & Receive
            </li>
            <li>
                Verfassen / Compose
            </li>
            <li>
                Adressbuch / Address book
            </li>
        </ul>
    </div>




    <div style="width: 400px; height: 300px; background-color: Green; display:block; float:left; margin: 0px; padding: 0px;">



       <iframe marginwidth="0" marginheight="0" hspace="0" vspace="0"  name="ifrmFolderContent" src="http://www.yahoo.com" frameborder="0" style="overflow: none; width: 400px; height: 150px; background-color: Orange; margin: 0px; padding: 0px;">

         Folder Content
       </iframe>



       <iframe marginwidth="0" marginheight="0" hspace="0" vspace="0"  name="ifrmEmail" src="http://www.msn.com" frameborder="0" style="overflow: none; width: 400px; height: 150px; background-color: Orange; margin: 0px; padding: 0px;">

         E-Mail Content

       </iframe>



    </div>



    <div style="background-color: Indigo; padding-top: 2mm; padding-bottom: 2mm; clear: left;">
        Copyright here
    </div>

</div>



</body>

</html>

It renders exactly as one would expect (Chrome + IE8).

But now, I add:

<!DOCTYPE html>

on top of it.

And suddenly, I get 2 to 5 mm of green space between the two iframes (folder content / email content), in both Chrome and IE8 (haven't tested FireFox).
What is even more disturbing, there seems to be no way to get rid of this space (except from removing <!DOCTYPE html>.

Why? I mean, the green comes from the background-color of the parent element, but why is there some space between the two iframes ?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

初见 2024-12-09 12:21:07

只需添加

<style>iframe { vertical-align:bottom; } </style>

<style>iframe { display:block; } </style>

即可将浏览器置于标准模式,其中内联元素放置在包含块的基线上,并且始终在行框中为字符下行部分分配空间。在其他模式下,仅当与 iframe 位于同一行上有可打印字符时才会创建该空间,但此处的情况并非如此。通过上述任一方法将 iframe 移离基线,可以将下降部分放置在 iframe 的高度内。

Just add

<style>iframe { vertical-align:bottom; } </style>

or

<style>iframe { display:block; } </style>

<!DOCTYPE html> puts the browser into standards mode, where inline elements are placed on the baseline of the containing block and a space for the character descenders is always allocated in the line box. In other modes, that space is only created when there are printable characters on the same line as the iframes which isn't the case here. Moving the iframe off the baseline by either of the methods above allows the space for the descenders to be placed within the height of the iframe.

栀子花开つ 2024-12-09 12:21:07

标准模式下的 iframe 默认情况下是 display: inline。这意味着它们将被放置在文本基线上,即。 “a”底部结束的位置,而不是“y”底部结束的位置。您看到的间隙是文本行中下降部分的空间。这应该删除它:

iframe { display: block; }

An iframe in standards mode is display: inline by default. That means they will be placed on the text baseline, ie. where the bottom of an 'a' ends, not where the bottom of a 'y' does. The gap you're seeing is the space for descenders in the line of text. This should remove it:

iframe { display: block; }
老娘不死你永远是小三 2024-12-09 12:21:07

只是一个快速说明(因为我在 IE 上遇到了这个问题)...

尝试设置:

font-size: 0px;

这有效(我相信是因为,正如有人建议的,iframe 位于文本基线上)。

祝大家好运!

Just a quick note (Because I was having this problem on IE)...

Trying setting:

font-size: 0px;

This worked (I believe because, as someone suggested, the iframes are places on the text baseline).

Goodluck y'all!

相守太难 2024-12-09 12:21:07

指定 seamless 属性,该属性是在 HTML 5 中引入的。 http: //www.quackit.com/html_5/tags/html_iframe_tag.cfm

Specify the seamless attribute, which is introduced in HTML 5. http://www.quackit.com/html_5/tags/html_iframe_tag.cfm

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文