我正在製作一個小型的個人學術網站,該網站具有多個網頁,並且具有相同的結構。具有共同標題和導航條的多個網頁
問題:有沒有辦法不重複每個html文件中的標題和菜單(或導航欄)的代碼?如果我可以將標題和菜單的代碼放在另一個文件中,例如header.html
並編寫一個語句,如\input{header.html}
(使用TeX語法)將文件包含到index.html
和publications.html
中。
下面是一個網站的例子。
的index.html
內容:的publications.html
<!DOCTYPE html>
<html>
<head>
<title>The Title</title>
<link type="text/css" rel="stylesheet" href="stylesheet.css">
</head>
<body>
<div id="header">
<h1>My Name</h1>
</div>
<div id="menu">
<p>
<a href="index.html">Home</a>
  
<a href="publications.html">Publications</a>
  
<a href="contact.html">Contact</a>
</p>
</div>
<div id="content">
<p>
This is my academic webpage.
</p>
<p>
I am a 15th year PhD student in Filmmaking at Mickey's Institute of Technology (MIT).
</p>
</div>
</body>
</html>
內容:中stylesheet.css
<!DOCTYPE html>
<html>
<head>
<title>The Title</title>
<link type="text/css" rel="stylesheet" href="stylesheet.css">
</head>
<body>
<div id="header">
<h1>My Name</h1>
</div>
<div id="menu">
<p>
<a href="index.html">Home</a>
  
<a href="publications.html">Publications</a>
  
<a href="contact.html">Contact</a>
</p>
</div>
<div id="content">
<ol>
<li>Snow White and the Seven Dwarfs, 1937</li>
<li>Pinocchio, 1940</li>
<li>The Reluctant Dragon, 1941</li>
</ol>
</div>
</body>
</html>
內容:
body {font-size: 16px; line-height: 20px; font-weight: light; color: #250517; /*gray*/}
a:link {text-decoration: none; color: #003399; /*blue*/}
a:visited {text-decoration: none; color: #003399; /*blue*/}
a:active {text-decoration: none; color: #003399; /*blue*/}
a:hover {text-decoration: none; color: #003399; /*blue*/}
#header {
width:800px;
margin-left:auto;
margin-right:auto;
text-align:center;
margin-top:50px;
}
#content {
width:730px;
margin-left:auto;
margin-right:auto;
height:410px;
}
#menu {
width:800px;
margin-left:auto;
margin-right:auto;
text-align:center;
margin-bottom:50px;
clear:both;
}
如果提供給您一個服務器端語言,如PHP,你可以使用包括。 – j08691
你甚至可以使用SSI,如果它支持:)。 – kapa
如果你沒有/不能使用服務器端代碼,那麼使用框架是你最好的選擇。不過,框架已棄用,我的意思是'iframe'來加載您的內容。休息靜態標題/菜單仍然在主頁面上。 – Abhitalks