使用iframe标签嵌入网页头部
时间: 2023-08-15 17:20:03 浏览: 68
您可以使用以下代码来使用 iframe 标签嵌入网页头部:
```html
<!DOCTYPE html>
<html>
<head>
<title>My Page</title>
<style>
#header {
height: 100px;
width: 100%;
background-color: #444;
color: #fff;
text-align: center;
line-height: 100px;
font-size: 36px;
}
</style>
</head>
<body>
<iframe src="header.html" frameborder="0" scrolling="no" width="100%"></iframe>
<div class="content">
<p>Here is the main content of the page.</p>
</div>
</body>
</html>
```
在这个例子中,我们创建了一个 id 为 header 的 div 元素作为网页头部,并将其样式设置为黑色背景、白色文字、居中对齐、高度为 100px 的标题栏。然后,我们使用 iframe 标签将 header.html 文件嵌入到我们的主 HTML 文件中,并将其设置为 100% 宽度以确保它与整个页面一样宽。最后,我们在主 HTML 文件中添加了一个 class 为 content 的 div 元素作为主要内容区域。