HTML 来显示目录链接页面使用 iframe
2025-04-24
23
参考资料
HTML iframe 元素详解
介绍
iframe (Inline Frame) 是 HTML 中用于在当前文档内嵌入另一个文档的标签。
基本标签
<iframe src="URL" width="px" height="px"></iframe>
主要属性
src: 指定要嵌入的文档 URLwidth: 设置 iframe 宽度height: 设置 iframe 高度name: 为 iframe 命名frameborder: 是否显示边框 (0/1)scrolling: 是否显示滚动条 (yes/no/auto)sandbox: 安全限制设置allowfullscreen: 是否允许全屏
基本用法
<iframe src="page.html" width="600" height="400"></iframe>
实例
嵌入外部网站
<iframe src="https://www.example.com" width="800" height="600"></iframe>
命名 iframe 用于链接目标
<iframe name="contentFrame" src="default.html"></iframe> <a href="page1.html" target="contentFrame">加载页面1</a>
功能扩展
使用 CSS 样式化 iframe
iframe {
border: 2px solid #ccc;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0,0,0,0.1);
}
iframe.responsive {
width: 100%;
height: auto;
aspect-ratio: 16/9;
}响应式 iframe
<div class="iframe-container">
<iframe src="video.html" allowfullscreen></iframe>
</div>
<style>
.iframe-container {
position: relative;
overflow: hidden;
width: 100%;
padding-top: 56.25%; /* 16:9 宽高比 */
}
.iframe-container iframe {
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
width: 100%;
height: 100%;
}
</style>使用 JavaScript 控制 iframe
// 获取 iframe 内容
var iframe = document.getElementById('myFrame');
var iframeDoc = iframe.contentDocument || iframe.contentWindow.document;
// 父窗口调用 iframe 函数
iframe.contentWindow.functionName();
// iframe 调用父窗口函数
parent.functionName();
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。
本文来自《西里网 . html 网页设计》 -- 发布时间:2025-03-29
本页链接:https://html.ciilii.com/show/news-1614.html
原创声明:本篇文章均为西里网原创,由《DeepSeek-R1 模型》自动生成。内容真实性仅供参考学习。
本作品采用 知识共享署名—非商业性使用—相同方式共享 4.0 国际许可协议 (CC BY-NC-SA 4.0) 进行许可。
