【问题标题】:Remove border from IFrame从 IFrame 中删除边框
【发布时间】:2010-09-09 01:34:41
【问题描述】:

如何从嵌入在我的网络应用程序中的 iframe 中删除边框? iframe 的一个例子是:

<iframe src="myURL" width="300" height="300">Browser not compatible.</iframe>

我希望从我的页面内容到 iframe 内容的过渡是无缝的,假设背景颜色是一致的。目标浏览器仅为 IE6,不幸的是,其他人的解决方案无济于事。

【问题讨论】:

  • 您可以使用iframe generator轻松做到这一点
  • 只需在

标签: html css iframe internet-explorer-6 noborder


【解决方案1】:

添加frameBorder 属性(注意大写“B”)。

所以它看起来像:

<iframe src="myURL" width="300" height="300" frameBorder="0">Browser not compatible.</iframe>

【讨论】:

  • 花了我一分钟才弄清楚在 JavaScript 中你只需要 element.frameBorder=0。没有 .style 并使用 0,而不是 '0'
  • 当使用Markup Validation Service 验证文档时,frameBorder 会导致错误,因为它不符合 HTML5:iframe 元素上的 frameborder 属性已过时。请改用 CSS。 在 HTML5 中,我将 CSS 属性设置为 border:0。有没有办法让它向后兼容而不导致验证错误?
  • @MartinAndersson caniuse.com/#feat=iframe-seamless 声明根本不支持。
  • 这里的答案是正确的,但是建议使用无缝属性的 cmets 不再正确。无缝属性已从规范中删除:w3.org/TR/2014/REC-html5-20141028/…
  • 请注意,虽然 JavaScript 属性是带有大写 B 的 frameBorder,但 HTML 属性实际上始终不区分大小写。在 XHTML 中,它应该全部小写 frameborder
【解决方案2】:

在 IE7 中疯狂尝试删除边框后,发现 frameBorder 属性区分大小写。

您必须将 frameBorder 属性设置为大写 B

<iframe frameBorder="0"></iframe>

【讨论】:

  • 注意:F12“调试器”中的 frameborder 属性更改不会被 IE6 显示。而是在 html 代码中添加属性。
  • 请注意,虽然 JavaScript 属性是带有大写 B 的 frameBorder,但 HTML 属性实际上始终不区分大小写。在 XHTML 中,它应该全部小写 frameborder
【解决方案3】:

根据iframe 文档,不推荐使用 frameBorder,并且首选使用“border”CSS 属性:

<iframe src="test.html" style="width: 100%; height: 400px; border: 0"></iframe>
  • 注意 CSS 边框属性在 IE6、7 或 8 中不能达到预期的效果。

【讨论】:

    【解决方案4】:

    除了添加 frameBorder 属性之外,您可能还需要考虑将滚动属性设置为“no”以防止出现滚动条。

    <iframe src="myURL" width="300" height="300" frameBorder="0" scrolling="no">Browser not compatible. </iframe > 
    

    【讨论】:

    • 它在 HTML5 中的等价物是什么?
    • style="overflow:hidden"
    【解决方案5】:

    对于特定于浏览器的问题,还可以根据 Dreamweaver 添加 frameborder="0" hspace="0" vspace="0" marginheight="0" marginwidth="0"

    <iframe src="test.html" name="banner" width="300" marginwidth="0" height="300" marginheight="0" align="top" scrolling="No" frameborder="0" hspace="0" vspace="0">Browser not compatible. </iframe>
    

    【讨论】:

      【解决方案6】:

      您可以在 iframe 代码中使用 style="border:0;"。这是在 HTML5 中删除边框的推荐方法。

      查看我的 html5 iframe generator 工具,无需编辑代码即可自定义 iframe。

      【讨论】:

        【解决方案7】:

        使用 HTML iframe 的 frameborder 属性

        http://www.w3schools.com/tags/att_iframe_frameborder.asp

        注意:IE 使用frameBorder(cap B),否则无法使用。但是,HTML5 不支持 iframe frameborder 属性。因此,请改用 CSS。

        <iframe src="http://example.org" width="200" height="200" style="border:0">
        

        您还可以使用滚动属性删除滚动 http://www.w3schools.com/tags/att_iframe_scrolling.asp

        <iframe src="http://example.org" width="200" height="200" scrolling="no" style="border:0">
        

        您还可以使用 HTML5 中新增的无缝属性。 iframe 标签的无缝属性仅在 Opera、Chrome 和 Safari 中受支持。如果存在,它指定 iframe 应该看起来像是包含文档的一部分(没有边框或滚动条)。目前,标签的无缝属性仅在 Opera、Chrome 和 Safari 中支持。但在不久的将来,它将成为标准解决方案,并将与所有浏览器兼容。 http://www.w3schools.com/tags/att_iframe_seamless.asp

        【讨论】:

          【解决方案8】:

          可以使用样式属性 对于 HTML5,如果您想删除框架的边框或任何可以使用样式属性的东西。如下所示

          代码放在这里

          <iframe src="demo.htm" style="border:none;"></iframe>
          

          【讨论】:

            【解决方案9】:

            添加 frameBorder 属性(大写“B”)。

            <iframe src="myURL" width="300" height="300" frameBorder="0">Browser not compatible. </iframe>
            

            【讨论】:

              【解决方案10】:

              您也可以通过这种方式使用 JavaScript。它会在 IE 和其他浏览器中找到任何 iframe 元素并删除它们的边框(尽管您可以在非 IE 浏览器中设置“border : none;”样式而不是使用 JavaScript)。并且即使在 iframe 生成并在文档中就位之后使用它也可以工作(例如,以纯 HTML 而不是 JavaScript 添加的 iframe)!

              这似乎可行,因为 IE 创建边框,而不是像您期望的那样在 iframe 元素上,而是在 iframe 的 CONTENT 上——在 iframe 在 BOM 中创建之后。 ($@&*#@!!! IE!!!)

              注意:只有当父窗口和 iframe 来自相同的来源(相同的域、端口、协议等)时,IE 部分才有效(当然)。否则脚本将在 IE 错误控制台中出现“拒绝访问”错误。如果发生这种情况,您唯一的选择是在生成之前设置它,正如其他人所指出的那样,或者使用非标准 frameBorder="0" 属性。 (或者只是让 IE 看​​起来很丑——我目前最喜欢的选项;))

              我花了好几个小时工作到绝望的地步才弄清楚这一点......

              享受。 :)

              // =========================================================================
              // Remove borders on iFrames
              
              var iFrameElements = window.document.getElementsByTagName("iframe");
              for (var i = 0; i < iFrameElements.length; i++)
              {
                iFrameElements[i].frameBorder="0";   //  For other browsers.
                iFrameElements[i].setAttribute("frameBorder", "0");   //  For other browsers (just a backup for the above).
                iFrameElements[i].contentWindow.document.body.style.border="none";   //  For IE.
              }
              

              【讨论】:

                【解决方案11】:

                我尝试了以上所有方法,如果这对您不起作用,请尝试以下 CSS 为我解决了问题。这只是告诉浏览器不要添加任何填充或边距。

                * {
                  padding:0px;
                  margin:0px;
                 }
                

                【讨论】:

                  【解决方案12】:

                  如果您放置 iframe 的页面的文档类型是 HTML5,那么您可以像这样使用seamless 属性:

                  <iframe src="..." seamless="seamless"></iframe>
                  

                  Mozilla docs on the seamless attribute

                  【讨论】:

                  • seams 是个好主意,但遗憾的是没有得到很好的支持。 caniuse.com/#search=seamless
                  • 完全不支持。
                  • 它甚至被从文档中删除了
                  【解决方案13】:

                  在你的样式表中添加

                  {
                    padding:0px;
                    margin:0px;
                    border: 0px
                  
                  }
                  

                  这也是一个可行的选择。

                  【讨论】:

                  • frameBorder 对我不起作用,但确实如此。谢谢。
                  【解决方案14】:

                  要么添加 frameBorder 属性,要么使用边框宽度为 0px; 的样式,或者将边框样式设置为无。

                  使用以下 3 个中的任何一个:

                  <iframe src="myURL" width="300" height="300" style="border-width:0px;">Browser not compatible.</iframe>
                  
                  <iframe src="myURL" width="300" height="300" frameborder="0">Browser not compatible.</iframe>
                  
                  <iframe src="myURL" width="300" height="300" style="border:none;">Browser not compatible.</iframe>

                  【讨论】:

                    【解决方案15】:

                    如果您使用 iFrame 来适应整个屏幕的宽度和高度,我假设您不是基于 300x300 尺寸,您还必须像这样将正文边距设置为“0”:

                    <body style="margin:0px;">
                    

                    【讨论】:

                      【解决方案16】:
                      <iframe src="mywebsite" frameborder="0" style="border: 0px solid white;">HTML iFrame is not compatible with your browser</iframe>
                      

                      这段代码应该在 HTML 4 和 5 中都可以工作。

                      【讨论】:

                        【解决方案17】:

                        同时设置border="0px"

                         <iframe src="yoururl" width="100%" height="100%" frameBorder="0"></iframe>
                        

                        【讨论】:

                          【解决方案18】:

                          试试

                          <iframe src="url" style="border:none;"></iframe>
                          

                          这将删除框架的边框。

                          【讨论】:

                            【解决方案19】:

                            使用这个

                            style="border:none;
                            

                            例子:

                            <iframe src="your.html" style="border:none;"></iframe>
                            

                            【讨论】:

                              【解决方案20】:

                              要移除边框,您可以使用 CSS 边框属性为 none。

                              <iframe src="myURL" width="300" height="300" style="border: none">Browser not compatible.</iframe>
                              

                              【讨论】:

                                【解决方案21】:

                                它很简单,只需在 iframe 标签中添加属性 frameborder = 0 &lt;iframe src="" width="200" height="200" frameborder="0"&gt;&lt;/iframe&gt;

                                【讨论】:

                                • 在回答问题之前,请务必阅读现有答案。这个答案已经提供了。不要重复答案,而是投票赞成现有的答案。可以在here 找到一些编写好答案的指南。
                                【解决方案22】:

                                1.Via Inline Style 设置边框:0

                                 <iframe src="display_file.html" style="height: 400px; width:
                                   100%;border: 0;">HTML iFrame is not compatible with your browser
                                   </iframe>
                                

                                2。通过标签属性 frameBorder Set 0

                                <iframe src="display_file.html" width="300" height="300" frameborder="0">Browser not compatible.</iframe>
                                

                                3.如果我们有多个 I Frame,我们可以在内部或外部给类和放置 css。

                                HTML:

                                <iframe src="display_file.html" class="no_border_iframe">
                                    HTML iFrame is not compatible with your browser 
                                </iframe>
                                

                                CSS:

                                <style>
                                .no_border_iframe{
                                border: 0; /* or border:none; */
                                }
                                </style>
                                

                                【讨论】:

                                  【解决方案23】:

                                  我遇到了底部白色边框的问题,我无法用边框、边距和填充规则修复它...所以添加 display:block; 因为 iframe 是一个内联元素。

                                  这会将 HTML 中的空格考虑在内。

                                  【讨论】:

                                    【解决方案24】:

                                    对我来说,添加效果很好

                                    .iframe{
                                    box-shadow: none !important;
                                    }
                                    

                                    此解决方案特别适用于我正在编辑的 shopify 主题。 shopify 主题在整个主题中以不同的方式使用 iframe,其中一种出现故障。我不得不手动进入 css 并覆盖 css 属性。

                                    【讨论】:

                                      【解决方案25】:
                                      iframe src="XXXXXXXXXXXXXXX"
                                      marginwidth="0" marginheight="0" width="xxx" height="xxx"
                                      

                                      适用于 Firefox ;)

                                      【讨论】:

                                      • 也许有不同的问题?
                                      【解决方案26】:
                                      <iframe src="URL" frameborder="0" width="100%" height="200">
                                      <p>Your browser does not support iframes.</p>
                                      </iframe>
                                      
                                      <iframe frameborder="1|0">
                                      
                                      (OR)
                                      
                                      <iframe src="URL" width="100%" height="300" style="border: none">Your browser 
                                      does not support iframes.</iframe>
                                      
                                      The <iframe> frameborder attribute is not supported in HTML5. Use CSS 
                                      instead.
                                      

                                      【讨论】:

                                        猜你喜欢
                                        • 1970-01-01
                                        • 1970-01-01
                                        • 1970-01-01
                                        • 2010-12-03
                                        • 2010-10-21
                                        • 1970-01-01
                                        • 1970-01-01
                                        • 1970-01-01
                                        • 1970-01-01
                                        相关资源
                                        最近更新 更多