从IFrame中删除边框

时间:2008-09-15 17:43:53

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

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

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

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

25 个答案:

答案 0 :(得分:1053)

添加frameBorder属性(请注意大写'B')。

所以它看起来像:

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

答案 1 :(得分:142)

在试图删除IE7中的边框后,我发现frameBorder属性区分大小写。

您必须使用大写 B 设置frameBorder属性。

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

答案 2 :(得分:65)

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

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

答案 3 :(得分:53)

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

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

答案 4 :(得分:21)

对于浏览器特定问题,请根据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>

答案 5 :(得分:9)

使用HTML iframe框架边界属性

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

注意:对IE使用框架 B 顺序(上限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

答案 6 :(得分:8)

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

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

答案 7 :(得分:7)

添加frameBorder属性(Capital'B')。

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

答案 8 :(得分:7)

可以使用样式属性 对于HTML5,如果要删除框架或任何内容的boder,可以使用style属性。如下所示

代码在这里

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

答案 9 :(得分:6)

如果您放置iframe的网页的文档类型是HTML5,那么您可以使用seamless属性,如下所示:

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

Mozilla docs on the seamless attribute

答案 10 :(得分:6)

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

这似乎有效,因为IE会创建边框,而不是iframe期望的iframe元素,而是iframe的内容 - 在BOM中创建iframe之后。 ($ @&amp; *#@ !!! IE !!!)

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

花了我几个小时的工作到绝望的地方来弄明白......

享受。 :)

// =========================================================================
// Remove borders on iFrames

if (window.document.getElementsByTagName("iframe"))
   {
      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 :(得分:5)

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

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

答案 12 :(得分:5)

在样式表中添加

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

}

这也是一个可行的选择。

答案 13 :(得分:4)

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

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

答案 14 :(得分:4)

<iframe src="mywebsite" frameborder="0" style="border: 0px solid white;">HTML iFrame is not compatible with your browser</iframe>

此代码应适用于HTML 4和5。

答案 15 :(得分:3)

还设置border =“0px”

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

答案 16 :(得分:2)

尝试

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

这将删除框架的边框。

答案 17 :(得分:2)

使用此

style="border:none;

示例:

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

答案 18 :(得分:2)

添加frameBorder属性,或使用border-width 0px;的样式,或将border样式设置为none。

使用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>

答案 19 :(得分:1)

要删除边框,可以使用CSS border属性为none。

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

答案 20 :(得分:1)

它简单只需在iframe标签中添加属性frameborder = 0 <iframe src="" width="200" height="200" frameborder="0"></iframe>

答案 21 :(得分:0)

1。通过内联样式设置边框:0

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

2。通过标记属性frameBorder设置0

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

3。如果我们有多个I框架,则可以在内部或外部进行类设置和放置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>

答案 22 :(得分:0)

我的底部白色边框有问题,我无法使用边框,边距和填充规则对其进行修复...所以添加display:block;,因为iframe是内联元素。

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

答案 23 :(得分:-1)

iframe src="XXXXXXXXXXXXXXX"
marginwidth="0" marginheight="0" width="xxx" height="xxx"

适用于Firefox;)

答案 24 :(得分:-1)

<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.
相关问题