使用iframe引入公共模块

新建一个公共文件head.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>头部</title>
<style>
body {
box-sizing: border-box;
margin: 0;
}
.header {
width: 100%;
height: 90px;
float: left;
background-color: red;
}
.list {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
.list li {
width: 20%;
height: 100%;
list-style: none;
float: left;
line-height: 90px;
text-align: center;
}
</style>
</head>
<body>
<div class="header">
<ul class="list">
<li>导航一</li>
<li>导航二</li>
<li>导航三</li>
<li>导航四</li>
<li>导航五</li>
</ul>
</div>
</body>
</html>

新建一个index.html,使用iframe引入head.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>引入其他页面</title>
<style>
body {
box-sizing: border-box;
margin: 0;
}
.content {
width: 100%;
height: 300px;
background-color: gray;
border: 1px;
}
iframe {
float: left;
}
</style>
</head>
<body>
<iframe src="head.html" frameborder="0" width="100%" height="90px" scrolling="no"></iframe>
<div class="content">
<span>这是内容</span>
</div>
</body>
</html>

备注:iframe的属性设置(摘自w3school)

align
  • left
  • right
  • top
  • middle
  • bottom

不赞成使用。请使用样式代替。

规定如何根据周围的元素来对齐此框架。

frameborder
  • 1
  • 0
规定是否显示框架周围的边框。
height
  • pixels
  • %
规定 iframe 的高度。
longdesc URL 规定一个页面,该页面包含了有关 iframe 的较长描述。
marginheight pixels 定义 iframe 的顶部和底部的边距。
marginwidth pixels 定义 iframe 的左侧和右侧的边距。
name frame_name 规定 iframe 的名称。
sandbox
  • ""
  • allow-forms
  • allow-same-origin
  • allow-scripts
  • allow-top-navigation
启用一系列对 <iframe> 中内容的额外限制。
scrolling
  • yes
  • no
  • auto
规定是否在 iframe 中显示滚动条。
seamless seamless 规定 <iframe> 看上去像是包含文档的一部分。
src URL 规定在 iframe 中显示的文档的 URL。
srcdoc HTML_code 规定在 <iframe> 中显示的页面的 HTML 内容。
width
  • pixels
  • %
定义 iframe 的宽度。
posted @ 2017-11-07 10:52  刘倩文  阅读(1696)  评论(0编辑  收藏  举报