简易css网页制作
创建基础HTML结构
使用文本编辑器创建一个index.html文件,写入以下基础HTML代码:
<!DOCTYPE html>
<html>
<head>
<title>简易网页</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<header>
<h1>网页标题</h1>
</header>
<nav>
<ul>
<li><a href="#">首页</a></li>
<li><a href="#">关于</a></li>
<li><a href="#">联系</a></li>
</ul>
</nav>
<main>
<section>
<h2>内容区域</h2>
<p>这里是网页的主要内容。</p>
</section>
</main>
<footer>
<p>版权信息 © 2023</p>
</footer>
</body>
</html>
添加基本CSS样式
创建styles.css文件,添加以下CSS规则:
body {
font-family: Arial, sans-serif;
line-height: 1.6;
margin: 0;
padding: 0;
color: #333;
}
header {
background: #35424a;
color: white;
padding: 20px 0;
text-align: center;
}
nav ul {
padding: 0;
list-style: none;
background: #e8491d;
text-align: center;
}
nav li {
display: inline;
}
nav a {
color: white;
text-decoration: none;
padding: 15px 20px;
display: inline-block;
}
main {
padding: 20px;
}
footer {
background: #35424a;
color: white;
text-align: center;
padding: 10px;
position: fixed;
bottom: 0;
width: 100%;
}
响应式布局调整
添加媒体查询使网页适应不同屏幕尺寸:
@media (max-width: 768px) {
nav li {
display: block;
}
nav a {
display: block;
padding: 10px;
}
footer {
position: static;
}
}
添加简单交互效果
为导航链接添加悬停效果:
nav a:hover {
background: #ccc;
color: #333;
}
使用Flexbox布局
改进导航栏的布局方式:

nav ul {
display: flex;
justify-content: center;
flex-wrap: wrap;
}
@media (max-width: 768px) {
nav ul {
flex-direction: column;
}
}
最终测试
在浏览器中打开index.html文件,检查网页在不同设备上的显示效果,确保布局合理,样式一致。可以通过调整浏览器窗口大小测试响应式效果,或使用开发者工具模拟不同设备尺寸。






