HTML 框架【iframe】

本节课,我们学习下HTML 框架【iframe】。

通过使用框架,你可以在同一个浏览器窗口中显示不止一个页面。

iframe语法

<iframe src="URL"></iframe>

该URL指向不同的网页。

iframe – 设置高度与宽度

height 和 width 属性用来定义iframe标签的高度与宽度。

属性默认以像素为单位, 但是你可以指定其按比例显示 (如:”80%”)。

<iframe loading="lazy" src="demo_iframe.htm" width="200" height="200"></iframe>

iframe – 移除边框

frameborder 属性用于定义iframe表示是否显示边框。

设置属性值为 “0” 移除iframe的边框:

<iframe src="demo_iframe.htm" frameborder="0"></iframe>

使用 iframe 来显示目标链接页面

iframe 可以显示一个目标链接的页面

目标链接的属性必须使用 iframe 的属性,如下实例:

<iframe src="demo_iframe.htm" name="iframe_a"></iframe>
<p><a href="https://www.web176.com" target="iframe_a" rel="noopener">Web176教程</a></p>

DEMO演示:

<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
<title>Web176教程(web176.com)</title> 
</head> 
<body>

<iframe src="demo_iframe.htm" name="iframe_a"></iframe>
<p><a href="https://www.web176.com" target="iframe_a">Web176教程</a></p>

<p><b>注意:</b> 因为 a 标签的 target 属性是名为 iframe_a 的 iframe 框架,所以在点击链接时页面会显示在 iframe框架中。</p>

</body>
</html>

HTML iframe 标签

标签说明
<iframe>定义一个内联的iframe

作者:terry,如若转载,请注明出处:https://www.web176.com/html4/7015.html

(0)
打赏 支付宝 支付宝 微信 微信
terryterry
上一篇 2022年10月12日 上午11:50
下一篇 2022年10月12日 下午2:08

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注