从IFrame移除边框

html CSS

西门GO村村

2020-03-16

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

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

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

第1821篇《从IFrame移除边框》来自Winter(https://github.com/aiyld/aiyld.github.io)的站点

23个回答
阿飞飞云 2020.03.16

其简单的只需在iframe代码frameborder = 0中添加属性 <iframe src="" width="200" height="200" frameborder="0"></iframe>

理查德伽罗 2020.03.16
iframe src="XXXXXXXXXXXXXXX"
marginwidth="0" marginheight="0" width="xxx" height="xxx"

适用于Firefox;)

村村伽罗十三 2020.03.16

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框架,我们可以在内部或外部给class和放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>
Gil蛋蛋 2020.03.16
<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.
Pro逆天猿 2020.03.16

要删除边框,可以将CSS border属性设置为none。

<iframe src="myURL" width="300" height="300" style="border: none">Browser not compatible.</iframe>
米亚逆天 2020.03.16

尝试

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

这将删除边框。

Stafan西门凯 2020.03.16

还设置border =“ 0px”

 <iframe src="yoururl" width="100%" height="100%" frameBorder="0"></iframe>
GO西里 2020.03.16

添加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>

Pro逆天猿 2020.03.16

用这个

style="border:none;

例:

<iframe src="your.html" style="border:none;"></iframe>
小哥前端 2020.03.16
<iframe src="mywebsite" frameborder="0" style="border: 0px solid white;">HTML iFrame is not compatible with your browser</iframe>

此代码在HTML 4和HTML 5中均应适用。

神无樱 2020.03.16

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

<body style="margin:0px;">
村村Gil 2020.03.16

您也可以使用JavaScript进行此操作。它将找到所有iframe元素,并在IE和其他浏览器中删除其边界(尽管您可以在非IE浏览器中设置“ border:none;”样式,而不使用JavaScript)。并且即使在生成iframe并将其放置在文档中之后,它也将起作用(例如,以纯HTML而非JavaScript添加的iframe)!

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

注意:(仅当)父窗口和iframe来自相同的来源(相同的域,端口,协议等)时,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.
         }
   }
梅蛋蛋 2020.03.16

在样式表中添加

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

}

这也是一个可行的选择。

飞云路易 2020.03.16

如果您要放置iframe的页面的文档类型是HTML5,则可以使用如下seamless属性:

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

Mozilla文档的Seamless属性

NearLHarry 2020.03.16

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

* {
  padding:0px;
  margin:0px;
 }
Itachi达蒙 2020.03.16

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

<iframe src="myURL" width="300" height="300" frameBorder="0">Browser not compatible. </iframe>
神奇伽罗Itachi 2020.03.16

如果要删除框架的边框或任何可以使用style属性的内容,可以将Style属性用于 HTML5。如下

代码在这里

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

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

查看我的html5 iframe生成器工具,以自定义iframe,而无需编辑代码。

小卤蛋Eva西门 2020.03.16

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

<iframe src="myURL" width="300" height="300" frameBorder="0" scrolling="no">Browser not compatible. </iframe > 
神奇番长 2020.03.16

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

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

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

<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>
ALPro 2020.03.16

使用HTML iframe frameborder属性

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中新增的Seamless属性。仅Opera,Chrome和Safari支持iframe标记的Seamless属性。如果存在,它指定iframe应该看起来像是包含文档的一部分(没有边框或滚动条)。到目前为止,只有Opera,Chrome和Safari支持该标签的Seamless属性。但是在不久的将来,它将成为标准解决方案,并将与所有浏览器兼容。http://www.w3schools.com/tags/att_iframe_seamless.asp

番长猴子 2020.03.16

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

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

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

问题类别

JavaScript Ckeditor Python Webpack TypeScript Vue.js React.js ExpressJS KoaJS CSS Node.js HTML Django 单元测试 PHP Asp.net jQuery Bootstrap IOS Android