制作一个响应式购书网页代码
时间: 2023-09-28 13:05:50 浏览: 87
好的,这里给出一个简单的响应式购书网页的HTML和CSS代码,实现了基本的页面布局和样式,你可以根据需要进行修改和完善。
HTML代码:
```html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>购书网页</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
</head>
<body>
<header>
<h1>购书网页</h1>
</header>
<nav>
<ul>
<li><a href="#">首页</a></li>
<li><a href="#">图书分类</a></li>
<li><a href="#">我的订单</a></li>
<li><a href="#">关于我们</a></li>
</ul>
</nav>
<main>
<section class="book-list">
<h2>图书列表</h2>
<ul>
<li>
<img src="book1.jpg" alt="book1">
<h3>图书名称1</h3>
<p>图书描述1</p>
<span class="price">¥50.00</span>
</li>
<li>
<img src="book2.jpg" alt="book2">
<h3>图书名称2</h3>
<p>图书描述2</p>
<span class="price">¥80.00</span>
</li>
<li>
<img src="book3.jpg" alt="book3">
<h3>图书名称3</h3>
<p>图书描述3</p>
<span class="price">¥60.00</span>
</li>
</ul>
</section>
<aside class="sidebar">
<h2>图书分类</h2>
<ul>
<li><a href="#">小说</a></li>
<li><a href="#">历史</a></li>
<li><a href="#">科幻</a></li>
<li><a href="#">教育</a></li>
</ul>
</aside>
</main>
<footer>
<p>© 2021 购书网页</p>
</footer>
</body>
</html>
```
CSS代码:
```css
/* 全局样式 */
body {
margin: 0;
padding: 0;
font-family: Arial, sans-serif;
font-size: 16px;
}
header, nav, main, aside, footer {
max-width: 1200px;
margin: 0 auto;
padding: 20px;
}
header {
background-color: #333;
color: #fff;
text-align: center;
}
nav {
background-color: #f8f8f8;
border-bottom: 1px solid #ddd;
}
nav ul {
list-style: none;
margin: 0;
padding: 0;
display: flex;
justify-content: space-between;
}
nav li {
margin: 0 10px;
}
nav a {
display: block;
padding: 10px;
color: #333;
text-decoration: none;
transition: background-color 0.3s ease;
}
nav a:hover {
background-color: #ddd;
}
main {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}
.book-list {
flex: 1;
margin-right: 20px;
}
.book-list h2 {
margin-top: 0;
}
.book-list ul {
list-style: none;
margin: 0;
padding: 0;
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}
.book-list li {
flex-basis: 30%;
margin-bottom: 20px;
text-align: center;
}
.book-list img {
width: 100%;
height: 200px;
object-fit: cover;
margin-bottom: 10px;
}
.book-list h3 {
margin: 0;
}
.book-list p {
margin: 10px 0;
color: #999;
}
.book-list .price {
display: block;
font-weight: bold;
color: #f00;
margin-top: 10px;
}
.sidebar {
flex-basis: 20%;
}
.sidebar h2 {
margin-top: 0;
}
.sidebar ul {
list-style: none;
margin: 0;
padding: 0;
}
.sidebar li {
margin-bottom: 10px;
}
.sidebar a {
color: #333;
text-decoration: none;
transition: color 0.3s ease;
}
.sidebar a:hover {
color: #f00;
}
footer {
background-color: #333;
color: #fff;
text-align: center;
padding: 10px;
}
/* 响应式设计 */
@media screen and (max-width: 768px) {
nav ul {
flex-direction: column;
}
nav li {
margin: 10px 0;
}
main {
flex-direction: column;
}
.book-list {
margin-right: 0;
}
.book-list li {
flex-basis: 45%;
}
.sidebar {
margin-top: 20px;
}
}
```
这个网页包含了一个头部、一个导航栏、一个内容区域和一个底部。内容区域包含了一个图书列表和一个侧边栏。使用了CSS媒体查询来实现响应式设计,使页面能够适应不同的屏幕尺寸和设备。
阅读全文