这个是简单的网站首页模板,用于学习或者参考
实现代码:
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>网站首页模板-Java小诚</title>
<style>
/* 重置默认样式 */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: Arial, sans-serif;
line-height: 1.6;
background-color: #f4f4f4;
color: #333;
}
header {
background: #007bff;
color: #fff;
padding: 1rem 0;
text-align: center;
position: sticky;
top: 0;
z-index: 1000;
}
nav ul {
list-style: none;
padding: 0;
}
nav ul li {
display: inline;
margin: 0 15px;
}
nav ul li a {
color: #fff;
text-decoration: none;
font-weight: bold;
transition: color 0.3s;
}
nav ul li a:hover {
color: #e2e2e2;
}
.container {
max-width: 1200px;
margin: 0 auto;
padding: 20px;
display: flex;
flex-wrap: wrap;
gap: 20px;
}
.card {
background: #fff;
border-radius: 8px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
overflow: hidden;
transition: transform 0.3s;
flex: 1 1 calc(33.333% - 20px);
margin: 10px;
}
.card img {
width: 100%;
height: auto;
}
.card-content {
padding: 15px;
}
.card-title {
font-size: 1.5rem;
margin-bottom: 10px;
}
.card-text {
font-size: 1rem;
color: #666;
}
.card:hover {
transform: scale(1.05);
}
.button {
display: inline-block;
padding: 10px 20px;
margin-top: 10px;
border: none;
border-radius: 4px;
background: #007bff;
color: #fff;
text-decoration: none;
text-align: center;
font-size: 16px;
cursor: pointer;
transition: background-color 0.3s;
}
.button:hover {
background: #0056b3;
}
footer {
background: #007bff;
color: #fff;
text-align: center;
padding: 15px 0;
font-size: 0.9rem;
}
/* 模态框样式 */
.modal {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.5);
justify-content: center;
align-items: center;
z-index: 2000;
}
.modal-content {
background: #fff;
border-radius: 8px;
padding: 20px;
width: 80%;
max-width: 500px;
position: relative;
}
.modal-close {
position: absolute;
top: 10px;
right: 10px;
font-size: 1.5rem;
cursor: pointer;
}
.modal-close:hover {
color: #007bff;
}
@media (max-width: 768px) {
nav ul li {
display: block;
margin: 10px 0;
}
.card {
flex: 1 1 100%;
}
}
</style>
</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>
</header>
<div class="container">
<div class="card">
<img src="https://via.placeholder.com/600x400" alt="示例图像">
<div class="card-content">
<h2 class="card-title">卡片标题 1</h2>
<p class="card-text">这是一些关于卡片内容的示例文本。它可以包含各种信息。</p>
<a href="#" class="button" onclick="openModal()">了解更多</a>
</div>
</div>
<div class="card">
<img src="https://via.placeholder.com/600x400" alt="示例图像">
<div class="card-content">
<h2 class="card-title">卡片标题 2</h2>
<p class="card-text">这是一些关于卡片内容的示例文本。它可以包含各种信息。</p>
<a href="#" class="button" onclick="openModal()">了解更多</a>
</div>
</div>
<div class="card">
<img src="https://via.placeholder.com/600x400" alt="示例图像">
<div class="card-content">
<h2 class="card-title">卡片标题 3</h2>
<p class="card-text">这是一些关于卡片内容的示例文本。它可以包含各种信息。</p>
<a href="#" class="button" onclick="openModal()">了解更多</a>
</div>
</div>
</div>
<footer>
<p>© 2024 高级网页示例. 版权所有.</p>
</footer>
<!-- 模态框 -->
<div id="modal" class="modal">
<div class="modal-content">
<span class="modal-close" onclick="closeModal()">×</span>
<h2>模态框标题</h2>
<p>这是模态框的内容区域。你可以在这里放置更多的内容。</p>
</div>
</div>
<script>
function openModal() {
document.getElementById('modal').style.display = 'flex';
}
function closeModal() {
document.getElementById('modal').style.display = 'none';
}
</script>
</body>
</html>