最简单的入门版 (纯HTML)

这个版本只有一个HTML文件,包含了最基本的个人介绍信息,非常适合初学者快速理解网页的结构。

html简单网页代码个人介绍
(图片来源网络,侵删)

特点:

  • 结构清晰,易于理解。
  • 使用了HTML5语义化标签 (<header>, <main>, <section>, <footer>)。
  • 包含了基本的个人信息、技能和联系方式。

代码 (index.html):

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">张三的个人介绍</title>
</head>
<body>
    <header>
        <h1>你好,我是张三</h1>
        <p>一名热爱编程的前端开发工程师</p>
    </header>
    <main>
        <section>
            <h2>关于我</h2>
            <p>我毕业于XX大学计算机科学专业,拥有3年的Web开发经验,我热衷于创造美观、高效且用户友好的网页应用,我相信,好的代码不仅要能运行,更要易于维护和扩展。</p>
        </section>
        <section>
            <h2>技能</h2>
            <ul>
                <li>HTML5, CSS3, JavaScript (ES6+)</li>
                <li>React, Vue.js</li>
                <li>Node.js, Express</li>
                <li>Git, Webpack</li>
            </ul>
        </section>
        <section>
            <h2>联系方式</h2>
            <p>邮箱: <a href="mailto:zhangsan@example.com">zhangsan@example.com</a></p>
            <p>GitHub: <a href="https://github.com/zhangsan" target="_blank">github.com/zhangsan</a></p>
        </section>
    </main>
    <footer>
        <p>&copy; 2025 张三. All rights reserved.</p>
    </footer>
</body>
</html>

如何使用:

  1. 将以上代码复制到一个文本编辑器中(如 VS Code, Sublime Text, 或记事本)。
  2. 保存为 index.html 文件。
  3. 用任何浏览器(如 Chrome, Firefox)打开这个文件,你就能看到一个简单的个人介绍页面。

添加了样式 (HTML + CSS)

这个版本在版本一的基础上,添加了CSS样式,让页面看起来更美观、专业。

html简单网页代码个人介绍
(图片来源网络,侵删)

特点:

  • HTML文件 (index.html): 结构保持不变,只关注内容。
  • CSS文件 (style.css): 所有样式都写在这个独立的文件中,实现了内容与样式的分离。
  • 包含了布局、颜色、字体、悬停效果等基本样式。

文件结构:

my-portfolio/
├── index.html
└── style.css

代码 1: index.html (与版本一相同)

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">张三的个人介绍</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <header>
        <h1>你好,我是张三</h1>
        <p>一名热爱编程的前端开发工程师</p>
    </header>
    <main>
        <section>
            <h2>关于我</h2>
            <p>我毕业于XX大学计算机科学专业,拥有3年的Web开发经验,我热衷于创造美观、高效且用户友好的网页应用,我相信,好的代码不仅要能运行,更要易于维护和扩展。</p>
        </section>
        <section>
            <h2>技能</h2>
            <ul>
                <li>HTML5, CSS3, JavaScript (ES6+)</li>
                <li>React, Vue.js</li>
                <li>Node.js, Express</li>
                <li>Git, Webpack</li>
            </ul>
        </section>
        <section>
            <h2>联系方式</h2>
            <p>邮箱: <a href="mailto:zhangsan@example.com">zhangsan@example.com</a></p>
            <p>GitHub: <a href="https://github.com/zhangsan" target="_blank">github.com/zhangsan</a></p>
        </section>
    </main>
    <footer>
        <p>&copy; 2025 张三. All rights reserved.</p>
    </footer>
</body>
</html>

代码 2: style.css (新增样式文件)

html简单网页代码个人介绍
(图片来源网络,侵删)
/* 全局样式重置和基础设置 */
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    line-height: 1.6;
    margin: 0;
    background-color: #f4f4f4;
    color: #333;
}
/* 容器布局 */
.container {
    width: 80%;
    max-width: 960px;
    margin: 20px auto;
    padding: 0 20px;
    background-color: #fff;
    border-radius: 8px;
    box-shadow: 0 0 15px rgba(0,0,0,0.1);
}
/* 页眉样式 */
header {
    background-color: #333;
    color: #fff;
    text-align: center;
    padding: 1rem 0;
    border-top-left-radius: 8px;
    border-top-right-radius: 8px;
}
header h1 {
    margin: 0;
    font-size: 2.5em;
}
header p {
    margin: 0;
    font-size: 1.2em;
    font-weight: 300;
}
区样式 */
main {
    padding: 2rem;
}
section {
    margin-bottom: 2rem;
}
section h2 {
    color: #333;
    border-bottom: 2px solid #eee;
    padding-bottom: 0.5rem;
}
/* 列表和链接样式 */
ul {
    list-style-type: none;
    padding-left: 0;
}
ul li {
    background: #f9f9f9;
    margin: 0.5rem 0;
    padding: 0.8rem;
    border-left: 3px solid #007bff;
}
a {
    color: #007bff;
    text-decoration: none;
    transition: color 0.3s ease;
}
a:hover {
    color: #0056b3;
    text-decoration: underline;
}
/* 页脚样式 */
footer {
    text-align: center;
    padding: 1rem;
    background-color: #333;
    color: #fff;
    border-bottom-left-radius: 8px;
    border-bottom-right-radius: 8px;
    margin-top: 0;
}

如何使用:

  1. 创建一个文件夹,my-portfolio
  2. 在文件夹中创建 index.html 文件,并粘贴上面的HTML代码。
  3. 在同一个文件夹中创建 style.css 文件,并粘贴上面的CSS代码。
  4. 用浏览器打开 index.html 文件。

现代单页版 (HTML + CSS + JavaScript)

这个版本添加了JavaScript,实现了一个平滑滚动到页面不同部分的导航栏,这是现代个人作品集网站的常见功能。

特点:

  • 固定导航栏: 导航栏始终在页面顶部。
  • 平滑滚动: 点击导航链接,页面会平滑地滚动到对应部分。
  • 活动链接指示: 当你滚动时,当前所在的导航项会高亮显示。
  • 响应式设计: 在小屏幕设备上(如手机)会自动调整为移动端布局。

文件结构:

modern-portfolio/
├── index.html
└── style.css

代码 1: index.html (新增了导航栏和JS)

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">张三的个人介绍</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <!-- 固定导航栏 -->
    <nav class="navbar">
        <a href="#about" class="nav-link">关于我</a>
        <a href="#skills" class="nav-link">技能</a>
        <a href="#contact" class="nav-link">联系方式</a>
    </nav>
    <main>
        <section id="about">
            <h1>你好,我是张三</h1>
            <p>一名热爱编程的前端开发工程师</p>
            <p>我毕业于XX大学计算机科学专业,拥有3年的Web开发经验,我热衷于创造美观、高效且用户友好的网页应用,我相信,好的代码不仅要能运行,更要易于维护和扩展。</p>
        </section>
        <section id="skills">
            <h2>技能</h2>
            <ul>
                <li>HTML5, CSS3, JavaScript (ES6+)</li>
                <li>React, Vue.js</li>
                <li>Node.js, Express</li>
                <li>Git, Webpack</li>
            </ul>
        </section>
        <section id="contact">
            <h2>联系方式</h2>
            <p>邮箱: <a href="mailto:zhangsan@example.com">zhangsan@example.com</a></p>
            <p>GitHub: <a href="https://github.com/zhangsan" target="_blank">github.com/zhangsan</a></p>
        </section>
    </main>
    <footer>
        <p>&copy; 2025 张三. All rights reserved.</p>
    </footer>
    <script>
        document.addEventListener('DOMContentLoaded', () => {
            const navLinks = document.querySelectorAll('.nav-link');
            const sections = document.querySelectorAll('section');
            // 平滑滚动
            navLinks.forEach(link => {
                link.addEventListener('click', (e) => {
                    e.preventDefault();
                    const targetId = link.getAttribute('href').substring(1);
                    const targetSection = document.getElementById(targetId);
                    if (targetSection) {
                        targetSection.scrollIntoView({
                            behavior: 'smooth'
                        });
                    }
                });
            });
            // 高亮当前所在区域的导航链接
            const highlightNav = () => {
                let current = '';
                sections.forEach(section => {
                    const sectionTop = section.offsetTop;
                    const sectionHeight = section.clientHeight;
                    if (scrollY >= (sectionTop - 200)) {
                        current = section.getAttribute('id');
                    }
                });
                navLinks.forEach(link => {
                    link.classList.remove('active');
                    if (link.getAttribute('href').substring(1) === current) {
                        link.classList.add('active');
                    }
                });
            };
            window.addEventListener('scroll', highlightNav);
        });
    </script>
</body>
</html>

代码 2: style.css (新增了导航栏样式和响应式设计)

/* (将版本二的所有CSS代码复制到这里) */
/* 导航栏样式 */
.navbar {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    background-color: #333;
    z-index: 1000; /* 确保导航栏在最上层 */
    padding: 1rem 0;
    text-align: center;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
.navbar .nav-link {
    color: #fff;
    text-decoration: none;
    margin: 0 15px;
    font-weight: 500;
    transition: color 0.3s ease, border 0.3s ease;
    padding: 0.5rem 1rem;
    border-bottom: 2px solid transparent;
}
.navbar .nav-link:hover,
.navbar .nav-link.active {
    color: #007bff;
    border-bottom-color: #007bff;
}
/* 为了给固定导航栏留出空间,给body添加上边距 */
body {
    padding-top: 70px; /* 导航栏高度 + 一些内边距 */
}
/* 响应式设计:适配手机屏幕 */
@media (max-width: 768px) {
    .container {
        width: 95%;
    }
    .navbar {
        padding: 0.5rem 0;
    }
    .navbar .nav-link {
        display: block; /* 在小屏幕上垂直排列 */
        margin: 5px 0;
    }
    body {
        padding-top: 120px; /* 手机上导航栏可能更高 */
    }
}

总结与建议

  • 新手入门: 从版本一开始,理解HTML的基本结构。
  • 学习样式: 使用版本二,学习如何用CSS美化你的页面,这是前端开发的核心技能。
  • 提升交互: 尝试版本三,了解JavaScript如何为页面增加动态效果,让用户体验更好。
  • 个性化: 无论选择哪个版本,请务必将内容(姓名、技能、链接等)替换成你自己的真实信息。
  • 下一步: 当你熟悉了这些基础后,可以尝试添加更多功能,
    • 一个展示你项目的 "作品集" (Portfolio) 部分。
    • 使用CSS Flexbox或Grid进行更复杂的布局。
    • 添加一张你的个人头像。
    • 学习使用CSS预处理器(如Sass)来组织你的CSS代码。