使用flex布局设计一个网页
时间: 2023-12-14 11:53:16 浏览: 92
好的,下面是一个简单的网页设计示例,使用flex布局:
HTML:
```
<!DOCTYPE html>
<html>
<head>
<title>Flex布局示例</title>
<style>
body {
margin: 0;
padding: 0;
}
header {
background-color: #333;
color: #fff;
height: 60px;
display: flex;
justify-content: space-between;
align-items: center;
padding: 0 20px;
}
nav {
background-color: #555;
color: #fff;
height: calc(100vh - 60px);
width: 200px;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
main {
background-color: #eee;
height: calc(100vh - 60px);
display: flex;
flex-wrap: wrap;
padding: 20px;
}
.box {
background-color: #fff;
border: 1px solid #ccc;
border-radius: 5px;
box-shadow: 2px 2px 5px rgba(0,0,0,0.1);
width: calc(33.33% - 20px);
margin: 10px;
padding: 20px;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
footer {
background-color: #333;
color: #fff;
height: 60px;
display: flex;
justify-content: center;
align-items: center;
}
</style>
</head>
<body>
<header>
<h1>Flex布局示例</h1>
<nav>
<ul>
<li><a href="#">链接1</a></li>
<li><a href="#">链接2</a></li>
<li><a href="#">链接3</a></li>
</ul>
</nav>
</header>
<main>
<div class="box">
<h2>盒子1</h2>
<p>这是一段文字。</p>
<button>按钮</button>
</div>
<div class="box">
<h2>盒子2</h2>
<p>这是一段文字。</p>
<button>按钮</button>
</div>
<div class="box">
<h2>盒子3</h2>
<p>这是一段文字。</p>
<button>按钮</button>
</div>
<div class="box">
<h2>盒子4</h2>
<p>这是一段文字。</p>
<button>按钮</button>
</div>
<div class="box">
<h2>盒子5</h2>
<p>这是一段文字。</p>
<button>按钮</button>
</div>
<div class="box">
<h2>盒子6</h2>
<p>这是一段文字。</p>
<button>按钮</button>
</div>
</main>
<footer>
<p>版权所有 © 2021</p>
</footer>
</body>
</html>
```
CSS:
```
body {
margin: 0;
padding: 0;
}
header {
background-color: #333;
color: #fff;
height: 60px;
display: flex;
justify-content: space-between;
align-items: center;
padding: 0 20px;
}
nav {
background-color: #555;
color: #fff;
height: calc(100vh - 60px);
width: 200px;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
main {
background-color: #eee;
height: calc(100vh - 60px);
display: flex;
flex-wrap: wrap;
padding: 20px;
}
.box {
background-color: #fff;
border: 1px solid #ccc;
border-radius: 5px;
box-shadow: 2px 2px 5px rgba(0,0,0,0.1);
width: calc(33.33% - 20px);
margin: 10px;
padding: 20px;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
footer {
background-color: #333;
color: #fff;
height: 60px;
display: flex;
justify-content: center;
align-items: center;
}
```
该示例包含一个顶部导航栏,一个侧边栏,一个主内容区域和一个底部页脚。主内容区域包含了6个盒子,使用了flex布局来实现等分排列。
阅读全文