我將創建一個現代化的響應式個人資料頁面,展示HTML在實際應用中的強大功能。這個頁面將包含多個實戰元素:導航欄、個人簡介、技能展示、作品集和聯系表單。
設計思路
-
使用Flexbox和Grid布局實現響應式設計
-
添加CSS過渡效果增強交互體驗
-
實現深色/淺色模式切換功能
-
創建懸停動畫效果提升視覺體驗
-
確保所有元素在不同設備上完美顯示
下面是完整的HTML代碼實現:
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>HTML實戰 - 響應式個人資料頁面</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
:root {
--primary: #4361ee;
--secondary: #3f37c9;
--accent: #4895ef;
--light: #f8f9fa;
--dark: #212529;
--text: #333;
--bg: #ffffff;
--card-bg: #f8f9fa;
--shadow: rgba(0, 0, 0, 0.1);
--transition: all 0.3s ease;
}
.dark-mode {
--primary: #4895ef;
--secondary: #4361ee;
--accent: #3f37c9;
--light: #343a40;
--dark: #f8f9fa;
--text: #f8f9fa;
--bg: #121212;
--card-bg: #1e1e1e;
--shadow: rgba(0, 0, 0, 0.3);
}
body {
background-color: var(--bg);
color: var(--text);
line-height: 1.6;
transition: var(--transition);
}
.container {
width: 90%;
max-width: 1200px;
margin: 0 auto;
padding: 0 20px;
}
/* 頭部樣式 */
header {
background: linear-gradient(135deg, var(--primary), var(--secondary));
color: white;
padding: 1rem 0;
position: sticky;
top: 0;
z-index: 100;
box-shadow: 0 2px 10px var(--shadow);
}
.header-container {
display: flex;
justify-content: space-between;
align-items: center;
}
.logo {
font-size: 1.8rem;
font-weight: 700;
display: flex;
align-items: center;
}
.logo i {
margin-right: 10px;
color: var(--accent);
}
nav ul {
display: flex;
list-style: none;
}
nav ul li {
margin-left: 1.5rem;
}
nav ul li a {
color: white;
text-decoration: none;
font-weight: 500;
padding: 8px 12px;
border-radius: 4px;
transition: var(--transition);
}
nav ul li a:hover {
background: rgba(255, 255, 255, 0.1);
}
.theme-toggle {
background: none;
border: none;
color: white;
font-size: 1.2rem;
cursor: pointer;
margin-left: 20px;
transition: var(--transition);
}
/* 英雄區域 */
.hero {
padding: 100px 0;
text-align: center;
background: linear-gradient(rgba(0,0,0,0.7), rgba(0,0,0,0.7)), url('https://images.unsplash.com/photo-1499951360447-b19be8fe80f5?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1170&q=80') center/cover no-repeat;
color: white;
}
.hero h1 {
font-size: 3.5rem;
margin-bottom: 1rem;
animation: fadeInDown 1s ease;
}
.hero p {
font-size: 1.5rem;
max-width: 700px;
margin: 0 auto 2rem;
animation: fadeInUp 1s ease;
}
.btn {
display: inline-block;
background: var(--accent);
color: white;
padding: 12px 30px;
border-radius: 50px;
text-decoration: none;
font-weight: 600;
transition: var(--transition);
border: 2px solid var(--accent);
animation: fadeIn 1.5s ease;
}
.btn:hover {
background: transparent;
transform: translateY(-3px);
box-shadow: 0 10px 20px rgba(0,0,0,0.1);
}
/* 關于區域 */
.section {
padding: 80px 0;
}
.section-title {
text-align: center;
margin-bottom: 60px;
}
.section-title h2 {
font-size: 2.5rem;
color: var(--primary);
position: relative;
display: inline-block;
padding-bottom: 15px;
}
.section-title h2::after {
content: '';
position: absolute;
bottom: 0;
l