写一个用HTML5和CSS3、JavaScript组成的体育用品电商网站的代码
时间: 2024-06-10 09:05:20 浏览: 154
我很抱歉,我是一个语言模型AI,我无法将编写完整代码的任务完成。但是,我可以尝试为您提供一些基本的HTML5,CSS3和JavaScript代码,以便您开始编写您的电商网站:
HTML5:
```
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Sports Goods E-commerce Website</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<header>
<div class="logo">
<h1>Sports Goods</h1>
</div>
<nav>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">Shop</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Contact</a></li>
</ul>
</nav>
</header>
<main>
<section class="banner">
<h2>Welcome to Sports Goods!</h2>
<p>Get all your sports needs fulfilled with us! </p>
</section>
<section class="products">
<h2>Our Products</h2>
<div class="product-items">
<!-- Product items will be added here -->
</div>
</section>
</main>
<footer>
<div class="logo">
<h1>Sports Goods</h1>
</div>
<nav>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">Shop</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Contact</a></li>
</ul>
</nav>
</footer>
<script src="script.js"></script>
</body>
</html>
```
CSS3:
```
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f2f2f2;
color: #333;
}
header {
background-color: #333;
color: #fff;
display: flex;
justify-content: space-between;
align-items: center;
padding: 10px 20px;
}
.logo {
display: inline-block;
}
nav ul {
display: flex;
list-style: none;
margin: 0;
padding: 0;
}
nav ul li {
margin-left: 20px;
}
nav ul li a {
color: #fff;
text-decoration: none;
}
h1, h2 {
font-weight: normal;
}
h2 {
margin: 40px 0 20px 0;
text-align: center;
}
.banner {
background-image: url("banner.jpg");
background-size: cover;
background-position: center;
height: 400px;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
.banner h2 {
font-size: 48px;
margin-bottom: 20px;
}
.banner p {
font-size: 24px;
}
footer {
background-color: #333;
color: #fff;
display: flex;
justify-content: space-between;
align-items: center;
padding: 10px 20px;
}
.products {
padding: 40px;
}
.product-items {
display: flex;
justify-content: space-between;
flex-wrap: wrap;
}
.product-item {
box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
width: calc(33.33% - 20px);
margin-bottom: 40px;
display: flex;
flex-direction: column;
}
.product-item img {
max-width: 100%;
}
.product-item h3 {
font-size: 24px;
margin: 20px 0 10px 0;
}
.product-item p {
margin: 0;
font-size: 16px;
flex-grow: 1;
}
.product-item button {
background-color: #333;
color: #fff;
border: none;
padding: 10px;
margin-top: 20px;
cursor: pointer;
transition: background 0.3s ease;
}
.product-item button:hover {
background-color: #fff;
color: #333;
}
```
JavaScript:
```
// Example code for fetching product data from API
fetch("https://example.com/products")
.then(function(response) {
return response.json();
})
.then(function(data) {
// Loop through data and generate HTML for each product item
for (var i = 0; i < data.length; i++) {
var productItem = document.createElement("div");
productItem.classList.add("product-item");
var productImage = document.createElement("img");
productImage.src = data[i].image;
var productName = document.createElement("h3");
productName.textContent = data[i].name;
var productDescription = document.createElement("p");
productDescription.textContent = data[i].description;
var buyButton = document.createElement("button");
buyButton.textContent = "Buy Now";
productItem.appendChild(productImage);
productItem.appendChild(productName);
productItem.appendChild(productDescription);
productItem.appendChild(buyButton);
var productItems = document.querySelector(".product-items");
productItems.appendChild(productItem);
}
})
.catch(function(error) {
console.log(error);
});
```
请注意,这些代码只是作为开始编写体育用品电商网站的基本框架部分,您需要根据您的需求进行修改和增强。希望这可以帮助您启动您的项目!
阅读全文