用html和css做网页完整代码
html<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Your Webpage Title</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f0f0f0;
}
header {
background-color: #333;
color: white;
padding: 10px;
text-align: center;
}
section {
max-width: 800px;
margin: 20px auto;
padding: 20px;
background-color: #fff;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
footer {
background-color: #333;
color: white;
padding: 10px;
text-align: center;
}
</style>
</head>
<body>
<header>
<h1>Your Website</h1>
</header>
<section>
<h2>Welcome to Your Website!</h2>
<p>This is a simple webpage created using HTML and CSS.</p>
<p>You can replace this content with your own.</p>
</section>
<footer>
<p>© 2024 Your Website. All rights reserved.</p>
</footer>
</body>
</html>
在这个例子中,<header>
元素包含网页的标题,<section>
元素包含网页的主要内容,<footer>
元素包含页脚信息。CSS用于样式化这些元素以及整个页面的背景和边距。
html<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Your Webpage Title</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f0f0f0;
}
header {
background-color: #333;
color: white;
padding: 10px;
text-align: center;
}
nav {
background-color: #666;
padding: 10px;
text-align: center;
}
nav a {
color: white;
text-decoration: none;
padding: 8px 16px;
margin: 0 8px;
border-radius: 4px;
background-color: #444;
}
section {
max-width: 800px;
margin: 20px auto;
padding: 20px;
background-color: #fff;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
footer {
background-color: #333;
color: white;
padding: 10px;
text-align: center;
}
</style>
</head>
<body>
<header>
<h1>Your Website</h1>
</header>
<nav>
<a href="#">Home</a>
<a href="#">About</a>
<a href="#">Services</a>
<a href="#">Contact</a>
</nav>
<section>
<h2>Welcome to Your Website!</h2>
<p>This is a simple webpage created using HTML and CSS.</p>
<p>You can replace this content with your own.</p>
</section>
<footer>
<p>© 2024 Your Website. All rights reserved.</p>
</footer>
</body>
</html>
在这个例子中,添加了一个导航栏 <nav>
,其中包含一些链接。链接具有样式,当鼠标悬停时,它们会稍微变暗。这是通过添加CSS规则实现的。
你可以根据你的需求继续扩展页面,例如添加更多的部分、图像、表格等。