多个html怎么导入相同的头部导航

1. iframe 包含法。
页头和页尾分别做成一个页面,然后通过iframe嵌入到调用的页面。这种方法在页头页尾高度固定的时候比较适用,因为当页头页尾高度不固定时,需要iframe根据页面内容自适应高度,比较麻烦。
简单代码结构示例:
<html>
<head>
<title>页面</title>
<style type="text/css">
.page{width:950px;margin:0 auto;}
</style>
</head>
<body>
<div class="page">
<iframe frameboder="0" scrolling="no" width="100%" height="80" src="head.html"></iframe>
<div>页面内容</div>
<iframe frameboder="0" scrolling="no" width="100%" height="80" src="foot.html"></iframe>
</div>
</body>
</html>
2. js包含法
页头和页尾改成外接js的形式,通过documen.write输出或其它js的输出的方法。这种方法在页头页尾需要修改时,不利于修改,也不好还原原先的html结构。
<html>
<head>
<title>页面</title>
<style type="text/css">
.page{width:950px;margin:0 auto;}
</style>
</head>
<body>
<div class="page">
<script type="text/javascript" href="head.js"></script>
<div>页面内容</div>
<script type="text/javascript" href="foot.js"></script>
</div>
</body>
</html>
3. shtml方法
运用服务端的包含方法,只需在页面中使用服务端包含命令<!--# include file="文件名称" -->,在被调用的页面嵌入页头和页脚即可。但此方法需要服务端支持ssi(server side include 服务端包含)功能。
<html>
<head>
<title>页面</title>
<style type="text/css">
.page{width:950px;margin:0 auto;}
</style>
</head>
<body>
<div class="page">
<!--#include file="head.html" -->
<div>页面内容</div>
<!--#include file="foot.html" -->
</div>
</body>
</html>

转载于:https://www.cnblogs.com/renyunbo/p/6053205.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值