html css js 宠物网站 代码 功能:登录注册,关于我们,宠物介绍,宠物商品
时间: 2024-03-22 14:40:21 浏览: 156
宠物网页
以下是一个简单的宠物网站的HTML、CSS和JavaScript代码,包括登录注册、关于我们、宠物介绍、宠物商品等功能。
HTML代码:
```html
<!DOCTYPE html>
<html>
<head>
<title>宠物网站</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" 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>
<div id="user">
<a href="#" id="login">登录</a>
<a href="#" id="register">注册</a>
</div>
</nav>
</header>
<main>
<section id="intro">
<h2>欢迎来到宠物世界</h2>
<p>我们致力于为您提供最好的宠物服务和产品,让您的爱宠生活更加美好。</p>
</section>
<section id="pet">
<h2>宠物介绍</h2>
<div class="pet-item">
<img src="dog.jpg" alt="狗狗">
<h3>狗狗</h3>
<p>狗狗是人类最忠诚的伙伴,它们陪伴我们走过人生的每一个阶段。</p>
</div>
<div class="pet-item">
<img src="cat.jpg" alt="猫咪">
<h3>猫咪</h3>
<p>猫咪是人类的好朋友,它们温顺可爱,是家庭中的重要成员。</p>
</div>
<div class="pet-item">
<img src="bird.jpg" alt="小鸟">
<h3>小鸟</h3>
<p>小鸟是生活中的美丽元素,它们能够带给我们无尽的快乐。</p>
</div>
</section>
<section id="product">
<h2>宠物商品</h2>
<div class="product-item">
<img src="dog-food.jpg" alt="狗粮">
<h3>狗粮</h3>
<p>我们提供各种口味、各种品牌的狗粮,保证您的爱宠健康成长。</p>
</div>
<div class="product-item">
<img src="cat-toy.jpg" alt="猫玩具">
<h3>猫玩具</h3>
<p>我们提供各种有趣的猫玩具,让您的猫咪不再无聊。</p>
</div>
<div class="product-item">
<img src="bird-cage.jpg" alt="鸟笼">
<h3>鸟笼</h3>
<p>我们提供各种款式、各种材质的鸟笼,让您的小鸟住得舒适。</p>
</div>
</section>
<section id="about">
<h2>关于我们</h2>
<p>我们是一家专业的宠物服务和产品提供商,我们的使命是为您的爱宠带来更好的生活。</p>
</section>
</main>
<footer>
<p>版权所有 © 2021 宠物网站</p>
</footer>
<div id="login-modal" class="modal">
<div class="modal-content">
<span class="close">×</span>
<h2>用户登录</h2>
<form>
<label for="username">用户名:</label>
<input type="text" id="username" name="username" required>
<label for="password">密码:</label>
<input type="password" id="password" name="password" required>
<input type="submit" value="登录">
</form>
</div>
</div>
<div id="register-modal" class="modal">
<div class="modal-content">
<span class="close">×</span>
<h2>用户注册</h2>
<form>
<label for="email">邮箱:</label>
<input type="email" id="email" name="email" required>
<label for="username">用户名:</label>
<input type="text" id="username" name="username" required>
<label for="password">密码:</label>
<input type="password" id="password" name="password" required>
<input type="submit" value="注册">
</form>
</div>
</div>
<script src="script.js"></script>
</body>
</html>
```
CSS代码:
```css
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: Arial, Helvetica, sans-serif;
}
header {
background: #333;
color: #fff;
padding: 20px;
}
h1 {
font-size: 32px;
}
nav {
display: flex;
justify-content: space-between;
align-items: center;
}
nav ul {
display: flex;
list-style: none;
}
nav ul li a {
color: #fff;
text-decoration: none;
padding: 10px;
}
nav ul li a:hover {
background: #fff;
color: #333;
}
#user {
display: flex;
align-items: center;
}
#user a {
color: #fff;
margin-left: 20px;
}
#user a:hover {
text-decoration: underline;
}
main {
padding: 20px;
display: flex;
flex-direction: column;
align-items: center;
}
h2 {
font-size: 24px;
margin-bottom: 20px;
}
section {
margin-bottom: 50px;
}
.pet-item {
display: flex;
flex-direction: column;
align-items: center;
margin-bottom: 20px;
}
.pet-item img {
width: 200px;
height: 200px;
object-fit: cover;
border-radius: 50%;
margin-bottom: 10px;
}
.product-item {
display: flex;
flex-direction: column;
align-items: center;
margin-bottom: 20px;
}
.product-item img {
width: 200px;
height: 200px;
object-fit: cover;
border-radius: 10px;
margin-bottom: 10px;
}
#login-modal, #register-modal {
display: none;
position: fixed;
z-index: 1;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: rgba(0,0,0,0.5);
}
.modal-content {
background-color: #fff;
margin: 10% auto;
padding: 20px;
border: 1px solid #888;
width: 50%;
}
.close {
color: #aaa;
float: right;
font-size: 28px;
font-weight: bold;
}
.close:hover, .close:focus {
color: black;
text-decoration: none;
cursor: pointer;
}
@media (max-width: 768px) {
header {
flex-direction: column;
align-items: center;
}
nav ul {
flex-direction: column;
margin-top: 20px;
}
nav ul li {
margin-bottom: 10px;
}
#user {
margin-top: 20px;
}
#login-modal .modal-content, #register-modal .modal-content {
width: 80%;
}
}
```
JavaScript代码:
```javascript
// 获取登录和注册按钮
var loginBtn = document.getElementById('login');
var registerBtn = document.getElementById('register');
// 获取登录和注册弹出框
var loginModal = document.getElementById('login-modal');
var registerModal = document.getElementById('register-modal');
// 获取关闭按钮
var loginClose = loginModal.getElementsByClassName('close')[0];
var registerClose = registerModal.getElementsByClassName('close')[0];
// 点击登录按钮弹出登录框
loginBtn.onclick = function() {
loginModal.style.display = 'block';
}
// 点击注册按钮弹出注册框
registerBtn.onclick = function() {
registerModal.style.display = 'block';
}
// 点击关闭按钮关闭弹出框
loginClose.onclick = function() {
loginModal.style.display = 'none';
}
registerClose.onclick = function() {
registerModal.style.display = 'none';
}
// 点击其他区域关闭弹出框
window.onclick = function(event) {
if (event.target == loginModal) {
loginModal.style.display = 'none';
}
if (event.target == registerModal) {
registerModal.style.display = 'none';
}
}
```
以上代码只是一个简单的示例,实际的宠物网站需要根据需求和具体情况进行修改和完善。
阅读全文