div css制作首页
使用DIV+CSS制作首页的步骤
规划页面结构 明确首页需要包含的模块,例如头部(header)、导航(nav)、内容区(content)、侧边栏(sidebar)、底部(footer)等。使用DIV标签划分这些区域。
编写HTML结构

<!DOCTYPE html>
<html>
<head>
<title>首页</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div id="header">头部区域</div>
<div id="nav">导航栏</div>
<div id="content">
<div class="main">主要内容</div>
<div class="sidebar">侧边栏</div>
</div>
<div id="footer">底部区域</div>
</body>
</html>
设计CSS样式 创建style.css文件,为各个DIV区域添加样式。使用CSS控制布局、颜色、字体等视觉效果。

body {
margin: 0;
padding: 0;
font-family: Arial, sans-serif;
}
#header {
background-color: #333;
color: white;
padding: 20px;
text-align: center;
}
#nav {
background-color: #444;
color: white;
padding: 10px;
}
#nav ul {
list-style-type: none;
margin: 0;
padding: 0;
}
#nav li {
display: inline;
margin-right: 15px;
}
#content {
overflow: hidden;
padding: 20px;
}
.main {
float: left;
width: 70%;
}
.sidebar {
float: right;
width: 25%;
}
#footer {
clear: both;
background-color: #333;
color: white;
text-align: center;
padding: 10px;
}
实现响应式设计 使用媒体查询确保首页在不同设备上都能良好显示。
@media screen and (max-width: 768px) {
.main, .sidebar {
float: none;
width: 100%;
}
}
添加交互效果 可以使用CSS伪类和过渡效果增强用户体验。
#nav a {
color: white;
text-decoration: none;
transition: color 0.3s;
}
#nav a:hover {
color: #ff9900;
}
优化和测试 检查各浏览器兼容性,确保布局在不同浏览器中表现一致。使用开发者工具调试CSS,优化加载性能。






