乐闻世界logo
搜索文章和话题

如何删除 iframe 的 border ?

7 个月前提问
3 个月前修改
浏览次数115

6个答案

1
2
3
4
5
6

要删除 HTML 中的 <iframe> 元素的边框,您可以通过 CSS 设置 border 属性为 0none。这里有两种方法可以实现:

方法 1:直接在 iframe 标签内使用 style 属性

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

或者

html
<iframe src="example.html" style="border:0;"></iframe>

方法 2:通过 CSS 文件或 <style> 标签

在 CSS 中,您可以为 iframe 指定一个类,然后为这个类设置 border 属性为 0none

html
<style> .no-border { border: none; } </style> <iframe class="no-border" src="example.html"></iframe>

或者,如果您想对页面中的所有 iframe 元素移除边框,您可以直接对 iframe 元素进行样式设定:

html
<style> iframe { border: 0; } </style> <iframe src="example.html"></iframe>

请根据您的具体需求选择合适的方法。如果您的 iframe 是通过 JavaScript 动态创建的,您也可以在创建 iframe 元素时设置其 style.border 属性。

2024年6月29日 12:07 回复

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

所以它看起来像:

shell
<iframe src="myURL" width="300" height="300" frameBorder="0">Browser not compatible.</iframe>
2024年6月29日 12:07 回复

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

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

shell
<iframe frameBorder="0"></iframe>
2024年6月29日 12:07 回复

根据iframe文档,frameBorder 已弃用,最好使用“border”CSS 属性:

shell
<iframe src="test.html" style="width: 100%; height: 400px; border: 0"></iframe>
  • 注意 CSS border 属性在 IE6、7 或 8 中无法达到预期效果**。**
2024年6月29日 12:07 回复

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

shell
<iframe src="myURL" width="300" height="300" frameBorder="0" scrolling="no">Browser not compatible. </iframe >
2024年6月29日 12:07 回复

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

shell
<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>
2024年6月29日 12:07 回复

你的答案