div css网页制作模板
div css网页制作模板
使用DIV和CSS制作网页模板是前端开发的基础,以下是一些常见的方法和示例代码:
基本结构
一个典型的DIV+CSS网页模板包含头部、主体内容和页脚:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>网页模板</title>
<style>
body {
margin: 0;
padding: 0;
font-family: Arial, sans-serif;
}
.header {
background-color: #333;
color: white;
padding: 20px;
text-align: center;
}
.content {
padding: 20px;
}
.footer {
background-color: #333;
color: white;
text-align: center;
padding: 10px;
position: fixed;
bottom: 0;
width: 100%;
}
</style>
</head>
<body>
<div class="header">
<h1>网站标题</h1>
</div>
<div class="content">
<p>这里是主要内容区域</p>
</div>
<div class="footer">
<p>版权信息 © 2023</p>
</div>
</body>
</html>
响应式布局
使用CSS媒体查询创建响应式设计:
.container {
width: 100%;
max-width: 1200px;
margin: 0 auto;
}
@media (max-width: 768px) {
.header {
font-size: 18px;
}
.content {
padding: 10px;
}
}
网格系统
创建简单的网格布局:
.row {
display: flex;
flex-wrap: wrap;
margin: 0 -15px;
}
.col {
padding: 0 15px;
box-sizing: border-box;
}
.col-4 {
width: 33.33%;
}
@media (max-width: 768px) {
.col-4 {
width: 100%;
}
}
导航菜单
水平导航菜单示例:
.nav {
background-color: #444;
overflow: hidden;
}
.nav a {
float: left;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.nav a:hover {
background-color: #ddd;
color: black;
}
卡片布局
创建卡片式内容区域:
.card {
box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2);
transition: 0.3s;
border-radius: 5px;
margin: 10px;
padding: 15px;
}
.card:hover {
box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2);
}
这些模板可以根据具体需求进行调整和扩展,构建各种类型的网页布局。







