商品首页HTML包括导航栏,搜索栏,商品网格布局添加CSS样式
时间: 2024-02-07 21:02:28 浏览: 20
好的,我可以帮你解答这个问题。首先,你需要创建一个HTML文件,并在文件中添加导航栏、搜索栏和商品网格布局。然后,你需要添加CSS样式来美化页面。
以下是一个示例HTML代码:
```html
<!DOCTYPE html>
<html>
<head>
<title>商品首页</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<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>
<div class="search">
<input type="text" placeholder="请输入商品名称">
<button>搜索</button>
</div>
</header>
<main>
<div class="product-grid">
<div class="product">
<img src="product1.jpg">
<h3>商品1</h3>
<p>¥99</p>
</div>
<div class="product">
<img src="product2.jpg">
<h3>商品2</h3>
<p>¥199</p>
</div>
<div class="product">
<img src="product3.jpg">
<h3>商品3</h3>
<p>¥299</p>
</div>
<div class="product">
<img src="product4.jpg">
<h3>商品4</h3>
<p>¥399</p>
</div>
<div class="product">
<img src="product5.jpg">
<h3>商品5</h3>
<p>¥499</p>
</div>
<div class="product">
<img src="product6.jpg">
<h3>商品6</h3>
<p>¥599</p>
</div>
</div>
</main>
</body>
</html>
```
接下来,你需要添加一个名为“style.css”的样式表文件,并在文件中添加以下CSS样式代码:
```css
/* 导航栏样式 */
nav {
background-color: #333;
color: #fff;
}
nav ul {
margin: 0;
padding: 0;
list-style: none;
display: flex;
}
nav li {
margin: 0 10px;
}
nav a {
display: block;
padding: 10px;
color: #fff;
text-decoration: none;
}
nav a:hover {
background-color: #fff;
color: #333;
}
/* 搜索栏样式 */
.search {
display: flex;
margin-top: 20px;
}
.search input[type="text"] {
flex: 1;
padding: 10px;
border: none;
border-radius: 5px 0 0 5px;
}
.search button {
padding: 10px;
border: none;
background-color: #333;
color: #fff;
border-radius: 0 5px 5px 0;
cursor: pointer;
}
.search button:hover {
background-color: #fff;
color: #333;
}
/* 商品网格布局样式 */
.product-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-gap: 20px;
margin-top: 20px;
}
.product {
display: flex;
flex-direction: column;
align-items: center;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
padding: 20px;
}
.product img {
width: 100%;
max-width: 200px;
height: auto;
margin-bottom: 10px;
}
.product h3 {
margin: 0;
font-size: 18px;
}
.product p {
margin: 10px 0 0;
font-size: 16px;
color: #f00;
font-weight: bold;
}
```
现在你的商品首页应该已经具备了导航栏、搜索栏和商品网格布局,并且已经应用了CSS样式。你可以根据自己的需求进行修改和调整。