HTML实现的简单网站首页模板

这个是简单的网站首页模板,用于学习或者参考

实现代码:

html 复制代码
<!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>&copy; 2024 高级网页示例. 版权所有.</p>
</footer>

<!-- 模态框 -->
<div id="modal" class="modal">
    <div class="modal-content">
        <span class="modal-close" onclick="closeModal()">&times;</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>
相关推荐
hunterandroid23 分钟前
[Android 从零到一] Compose LazyColumn 性能优化:key、稳定性与重组治理
android·前端
lichenyang45332 分钟前
从一次团队邀请开始:用 React、NestJS 与 Socket.IO 做可靠的实时通知
前端
vtian33 分钟前
一篇文章吃透 Monorepo:pnpm + Turborepo + Changesets 全流程实战(含 8 个踩坑)
前端
默_笙38 分钟前
❗ 点击计数按钮,为什么"峨眉队"也跟着重新渲染?React.memo 说:我记住了
前端·javascript
31535669131 小时前
DeepSeek Harness 发布后,我没急着跑 Demo,先把 `.agents/` 翻了一遍
前端·后端·github
名字还没想好☜1 小时前
Next.js 用 Server Components 直连数据库:去掉 API 层的边界,和三条别踩的安全红线
前端·javascript·数据库·安全·react·next.js
学习zhao极致it1 小时前
2020全新React教程全家桶实战redux+antd+React Hooks前端js视频
前端
用户921080262861 小时前
Bubble 消息操作区改造:复制、重新生成和反馈
前端
LEE1 小时前
AI Agent 都在疯狂加功能,它说:我全砍了
前端·后端
张清悠2 小时前
用 TRAE Work 把 PRD + 设计稿注释,整理成 20 分钟可排期前端任务清单
前端