html和css网上书店代码
时间: 2024-11-13 21:16:21 浏览: 1
HTML和CSS是用于网页开发的两个基本技术。HTML是网页的骨架,定义了网页的结构和内容,而CSS则是网页的样式表,定义了网页的外观和布局。下面是一个简单的HTML和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>
<li><a href="#">联系我们</a></li>
</ul>
</nav>
</header>
<main>
<section class="book-list">
<h2>热门图书</h2>
<ul>
<li>
<img src="book1.jpg" alt="图书封面">
<h3>图书名称</h3>
<p>图书描述信息</p>
<button>加入购物车</button>
</li>
<li>
<img src="book2.jpg" alt="图书封面">
<h3>图书名称</h3>
<p>图书描述信息</p>
<button>加入购物车</button>
</li>
<li>
<img src="book3.jpg" alt="图书封面">
<h3>图书名称</h3>
<p>图书描述信息</p>
<button>加入购物车</button>
</li>
</ul>
</section>
<section class="search-box">
<h2>搜索图书</h2>
<form action="#" method="get">
<input type="text" name="search" placeholder="输入关键字...">
<button type="submit">搜索</button>
</form>
</section>
</main>
<footer>
Copyright © 网上书店
</footer>
</body>
</html>
```
CSS部分:
```css
body {
margin: 0;
padding: 0;
font-family: Arial, sans-serif;
}
header {
background-color: #333;
color: #fff;
padding: 20px;
}
nav ul {
list-style: none;
margin: 0;
padding: 0;
display: flex;
}
nav ul li {
margin-right: 20px;
}
nav ul li a {
color: #fff;
text-decoration: none;
}
main {
padding: 20px;
display: flex;
flex-wrap: wrap;
}
.book-list {
flex-grow: 1;
flex-basis: 70%;
margin-right: 20px;
}
.book-list h2 {
font-size: 24px;
}
.book-list ul {
list-style: none;
margin: 0;
padding: 0;
display: flex;
flex-wrap: wrap;
}
.book-list li {
flex-basis: calc(33.33% - 10px);
margin-bottom: 20px;
padding: 10px;
background-color: #f5f5f5;
border-radius: 5px;
box-shadow: 2px 2px 5px rgba(0,0,0,0.3);
}
.book-list li img {
width: 100%;
height: auto;
margin-bottom: 10px;
}
.book-list li h3 {
font-size: 18px;
margin-bottom: 10px;
}
.book-list li p {
font-size: 14px;
margin-bottom: 10px;
}
.book-list li button {
background-color: #333;
color: #fff;
border: none;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
}
.search-box {
flex-grow: 1;
flex-basis: 30%;
background-color: #f5f5f5;
border-radius: 5px;
padding: 20px;
box-shadow: 2px 2px 5px rgba(0,0,0,0.3);
}
.search-box h2 {
font-size: 24px;
margin-bottom: 10px;
}
.search-box input[type=text] {
width: 100%;
padding: 10px;
border-radius: 5px;
border: none;
margin-bottom: 10px;
}
.search-box button[type=submit] {
background-color: #333;
color: #fff;
border: none;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
}
footer {
background-color: #333;
color: #fff;
padding: 20px;
text-align: center;
}
```
阅读全文