利用div+css完成网页布局
时间: 2023-05-27 20:06:13 浏览: 66
以下是一个简单的网页布局,使用div和css实现:
HTML代码:
```html
<!DOCTYPE html>
<html>
<head>
<title>网页布局</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<header>
<h1>网页标题</h1>
<nav>
<ul>
<li><a href="#">首页</a></li>
<li><a href="#">分类</a></li>
<li><a href="#">关于我们</a></li>
</ul>
</nav>
</header>
<main>
<section>
<h2>最新文章</h2>
<article>
<h3>文章标题</h3>
<p>文章内容</p>
</article>
<article>
<h3>文章标题</h3>
<p>文章内容</p>
</article>
<article>
<h3>文章标题</h3>
<p>文章内容</p>
</article>
</section>
<aside>
<h2>侧边栏</h2>
<ul>
<li><a href="#">链接1</a></li>
<li><a href="#">链接2</a></li>
<li><a href="#">链接3</a></li>
<li><a href="#">链接4</a></li>
</ul>
</aside>
</main>
<footer>
<p>版权信息</p>
</footer>
</body>
</html>
```
CSS代码:
```css
/* 全局样式 */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: Arial, sans-serif;
font-size: 16px;
}
/* 头部样式 */
header {
background-color: #333;
color: #fff;
padding: 20px;
}
header h1 {
font-size: 28px;
margin: 0;
}
nav ul {
list-style: none;
margin: 0;
padding: 0;
display: flex;
}
nav li {
margin-right: 20px;
}
nav a {
color: #fff;
text-decoration: none;
}
/* 主体样式 */
main {
max-width: 960px;
margin: 0 auto;
display: flex;
flex-wrap: wrap;
justify-content: space-between;
padding: 20px;
}
section {
flex-basis: 70%;
}
section h2 {
font-size: 24px;
margin-bottom: 10px;
}
article {
margin-bottom: 20px;
}
article h3 {
font-size: 20px;
margin-bottom: 10px;
}
aside {
flex-basis: 25%;
}
aside ul {
list-style: none;
margin: 0;
padding: 0;
}
aside li {
margin-bottom: 10px;
}
aside a {
color: #333;
text-decoration: none;
}
/* 底部样式 */
footer {
background-color: #333;
color: #fff;
padding: 20px;
text-align: center;
}
```