使用flex布局,编写4399游戏网
时间: 2023-07-07 17:38:41 浏览: 187
很高兴回答您的问题!以下是使用flex布局编写4399游戏网的示例代码:
HTML代码:
```
<div class="container">
<header>
<a href="#" class="logo">4399游戏网</a>
<nav>
<ul>
<li><a href="#">首页</a></li>
<li><a href="#">分类</a></li>
<li><a href="#">排行榜</a></li>
<li><a href="#">活动</a></li>
<li><a href="#">新闻</a></li>
<li><a href="#">论坛</a></li>
</ul>
</nav>
</header>
<main>
<section class="banner">
<img src="banner.jpg" alt="游戏banner">
</section>
<section class="games">
<h2>热门游戏</h2>
<ul>
<li>
<a href="#">
<img src="game1.jpg" alt="游戏1">
<span>游戏1</span>
</a>
</li>
<li>
<a href="#">
<img src="game2.jpg" alt="游戏2">
<span>游戏2</span>
</a>
</li>
<li>
<a href="#">
<img src="game3.jpg" alt="游戏3">
<span>游戏3</span>
</a>
</li>
<li>
<a href="#">
<img src="game4.jpg" alt="游戏4">
<span>游戏4</span>
</a>
</li>
</ul>
</section>
</main>
<footer>
<p>版权所有 © 4399游戏网</p>
</footer>
</div>
```
CSS代码:
```
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: Arial, sans-serif;
font-size: 16px;
}
.container {
display: flex;
flex-direction: column;
min-height: 100vh;
}
header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 20px;
background-color: #fff;
box-shadow: 0 3px 10px rgba(0, 0, 0, 0.1);
}
.logo {
font-size: 24px;
font-weight: bold;
color: #f00;
text-decoration: none;
}
nav ul {
display: flex;
list-style: none;
}
nav li {
margin-left: 10px;
}
nav a {
color: #333;
text-decoration: none;
}
nav a:hover {
color: #f00;
}
main {
flex: 1;
padding: 20px;
background-color: #fff;
}
.banner img {
width: 100%;
}
.games h2 {
font-size: 20px;
font-weight: bold;
margin-bottom: 10px;
}
.games ul {
display: flex;
flex-wrap: wrap;
list-style: none;
}
.games li {
width: calc(25% - 10px);
margin-right: 10px;
margin-bottom: 20px;
}
.games li:last-child {
margin-right: 0;
}
.games a {
display: block;
text-align: center;
text-decoration: none;
}
.games img {
width: 100%;
}
.games span {
display: block;
margin-top: 10px;
font-size: 14px;
color: #666;
}
footer {
display: flex;
justify-content: center;
align-items: center;
height: 50px;
background-color: #f00;
color: #fff;
}
```
以上代码实现了一个简单的4399游戏网页面,使用了flex布局实现了响应式布局,适应不同设备的屏幕尺寸。
阅读全文