简体   繁体   English

从 IFrame 移除边框

[英]Remove border from IFrame

How would I remove the border from an iframe embedded in my web app?如何从嵌入在我的 web 应用程序中的 iframe 中删除边框? An example of the iframe is: iframe 的示例是:

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

I would like the transition from the content on my page to the contents of the iframe to be seamless, assuming the background colors are consistent.假设背景 colors 是一致的,我希望从我页面上的内容到 iframe 内容的过渡是无缝的。 The target browser is IE6 only and unfortunately solutions for others will not help.目标浏览器仅限 IE6,不幸的是,其他人的解决方案无济于事。

Add the frameBorder attribute (note the capital 'B' ).添加frameBorder属性(注意大写的 'B' )。

So it would look like:所以它看起来像:

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

After going mad trying to remove the border in IE7, I found that the frameBorder attribute is case sensitive.在 IE7 中尝试删除边框后,我发现 frameBorder 属性区分大小写。

You have to set the frameBorder attribute with a capital B .您必须使用大写B设置 frameBorder 属性。

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

As per iframe documentation, frameBorder is deprecated and using the "border" CSS attribute is preferred:根据iframe文档,不推荐使用 frameBorder 并首选使用“border” CSS 属性:

<iframe src="test.html" style="width: 100%; height: 400px; border: 0"></iframe>
  • Note CSS border property does not achieve the desired results in IE6, 7 or 8.注意 CSS 边框属性在 IE6、7 或 8 中没有达到预期的效果。

In addition to adding the frameBorder attribute you might want to consider setting the scrolling attribute to "no" to prevent scrollbars from appearing.除了添加 frameBorder 属性之外,您可能还需要考虑将滚动属性设置为“no”以防止出现滚动条。

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

For browser specific issues also add frameborder="0" hspace="0" vspace="0" marginheight="0" marginwidth="0" according to Dreamweaver:对于浏览器特定问题,还根据 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>

You can use style="border:0;"您可以使用style="border:0;" in your iframe code.在您的 iframe 代码中。 That is the recommended way to remove border in HTML5.这是在 HTML5 中移除边框的推荐方法。

Check out my html5 iframe generator tool to customize your iframe without editing code.查看我的html5 iframe 生成器工具,无需编辑代码即可自定义 iframe。

Use the HTML iframe frameborder Attribute使用 HTML iframe frameborder 属性

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

Note: use frame B order (cap B) for IE, otherwise will not work.注意:IE 使用框架B顺序(cap B),否则将不起作用。 But, the iframe frameborder attribute is not supported in HTML5.但是,HTML5 不支持 iframe frameborder 属性。 So, Use CSS instead.因此,请改用 CSS。

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

you can also remove scrolling using scrolling attribute http://www.w3schools.com/tags/att_iframe_scrolling.asp您还可以使用滚动属性http://www.w3schools.com/tags/att_iframe_scrolling.asp删除滚动

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

Also you can use seamless attribute which is new in HTML5.您也可以使用 HTML5 中新增的无缝属性。 The seamless attribute of the iframe tag is only supported in Opera, Chrome and Safari. iframe 标签的无缝属性仅在 Opera、Chrome 和 Safari 中受支持。 When present, it specifies that the iframe should look like it is a part of the containing document (no borders or scrollbars).如果存在,它指定 iframe 应该看起来像是包含文档的一部分(没有边框或滚动条)。 As of now, The seamless attribute of the tag is only supported in Opera, Chrome and Safari.目前,标签的无缝属性仅在 Opera、Chrome 和 Safari 中支持。 But in near future it will be the standard solution and will be compatible with all browsers.但在不久的将来,它将成为标准解决方案,并将与所有浏览器兼容。 http://www.w3schools.com/tags/att_iframe_seamless.asp http://www.w3schools.com/tags/att_iframe_seamless.asp

Style property can be used For HTML5 if you want to remove the boder of your frame or anything you can use the style property. Style 属性可以用于HTML5 如果你想删除你的框架的边框或任何你可以使用 style 属性的东西。 as given below如下所示

Code goes here代码在这里

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

You can also do it with JavaScript this way.您也可以通过这种方式使用 JavaScript 进行操作。 It will find any iframe elements and remove their borders in IE and other browsers (though you can just set a style of "border: none;" in non-IE browsers instead of using JavaScript).它将找到任何 iframe 元素并在 IE 和其他浏览器中删除它们的边框(尽管您可以在非 IE 浏览器中设置“边框:无”样式而不是使用 JavaScript)。 AND it will work even if used AFTER the iframe is generated and in place in the document (eg iframes that are added in plain HTML and not JavaScript)!并且即使在生成 iframe 并在文档中就位之后使用它也可以工作(例如,在纯 HTML 而不是 JavaScript 中添加的 iframe)!

This appears to work because IE creates the border, not on the iframe element as you'd expect, but on the CONTENT of the iframe--after the iframe is created in the BOM.这似乎可行,因为 IE 创建了边框,而不是像您期望的那样在 iframe 元素上,而是在 iframe 的内容上——在 BOM 中创建 iframe 之后。 ($@&*#@!!! IE!!!) ($@&*#@!!! IE!!!)

Note: The IE part will only work (of course) if the parent window and iframe are from the SAME origin (same domain, port, protocol etc.).注意:IE 部分只有在父 window 和 iframe 来自相同的来源(相同的域、端口、协议等)时才有效(当然)。 Otherwise the script will get "access denied" errors in the IE error console.否则脚本将在 IE 错误控制台中出现“拒绝访问”错误。 If that happens, your only option is to set it before it is generated, as others have noted, or use the non-standard frameBorder="0" attribute.如果发生这种情况,您唯一的选择是在生成之前设置它,正如其他人所指出的那样,或者使用非标准 frameBorder="0" 属性。 (or just let IE look fugly--my current favorite option;) ) (或者只是让 IE 看起来很丑——我目前最喜欢的选项;))

Took me MANY hours of working to the point of despair to figure this out...我花了很多时间工作到绝望的地步来解决这个问题......

Enjoy.享受。 :) :)

// =========================================================================
// 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.
}

I tried all of the above and if that doesn't work for you try the below CSS resolved the issue for me.我尝试了以上所有方法,如果这对您不起作用,请尝试下面的 CSS 为我解决了这个问题。 Which just tells the browsers to not add any padding or margin.这只是告诉浏览器不要添加任何填充或边距。

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

Add the frameBorder attribute (Capital 'B').添加 frameBorder 属性(大写“B”)。

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

In your stylesheet add在您的样式表中添加

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

}

This is also a viable option.这也是一个可行的选择。

Either add the frameBorder attribute, or use style with border-width 0px;, or set border style equal to none.添加 frameBorder 属性,或使用边框宽度为 0px 的样式;或将边框样式设置为无。

use any one from below 3:使用以下 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>

If the doctype of the page you are placing the iframe on is HTML5 then you can use the seamless attribute like so:如果您放置 iframe 的页面的文档类型是 HTML5,那么您可以像这样使用seamless属性:

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

Mozilla docs on the seamless attribute 关于无缝属性的 Mozilla 文档

If you are using the iFrame to fit the width and height of the entire screen, which I am assuming you are not based on the 300x300 size, you must also set the body margins to "0" like this:如果您使用 iFrame 来适应整个屏幕的宽度和高度,我假设您不是基于 300x300 大小,您还必须将正文边距设置为“0”,如下所示:

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

This code should work in both HTML 4 and 5.此代码应在 HTML 4 和 5 中均有效。

also set border="0px "还设置边框=“0px”

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

Try尝试

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

This will remove the border of your frame.这将删除框架的边框。

Use this用这个

style="border:none;

Example:例子:

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

To remove border you can use CSS border property to none.要删除边框,您可以使用 CSS 边框属性为无。

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

1.Via Inline Style set border: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. Via Tag Attribute frameBorder Set 0 2.通过标签属性frameBorder Set 0

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

3. if We have multiple I Frame We can give class and Put css in internal or externally. 3.如果我们有多个I帧我们可以给class和把css放在内部或外部。

HTML: HTML:

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

CSS: CSS:

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

Its simple just add attribute in iframe tag frameborder = 0 <iframe src="" width="200" height="200" frameborder="0"></iframe>它很简单,只需在 iframe 标签中添加属性 frameborder = 0 <iframe src="" width="200" height="200" frameborder="0"></iframe>

for me, adding worked perfectly对我来说,添加效果很好

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

this solution is particularly for a shopify theme I am editing.此解决方案特别适用于我正在编辑的 shopify 主题。 The shopify theme uses iframes in different ways throughout the whole theme and one of them glitched. shopify 主题在整个主题中以不同方式使用 iframe,其中一种出现故障。 I had to go into the css manually and overide the css attribute.我必须手动将 go 放入 css 并覆盖 css 属性。

I had an issue with bottom white border and i could not fix it with border, margin & padding rules... So add display:block;我遇到了底部白色边框的问题,我无法用边框、边距和填充规则修复它......所以添加display:block; because iframe is an inline element.因为 iframe 是一个内联元素。

This takes whitespace in your HTML into account.这会将 HTML 中的空格考虑在内。

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

Works with Firefox;)适用于 Firefox;)

<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.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM