HTML/CSS新手必学:打造精美个人主页

基础HTML结构

创建一个简单的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>个人主页</title>
    <link rel="stylesheet" href="styles.css">
</head>
<body>
    <header>
        <h1>你的名字</h1>
        <p>职业/身份简介</p>
    </header>
    <main>
        <section class="about">
            <h2>关于我</h2>
            <p>这里写一段自我介绍。</p>
        </section>
        <section class="skills">
            <h2>技能</h2>
            <ul>
                <li>HTML/CSS</li>
                <li>其他技能项</li>
            </ul>
        </section>
    </main>
    <footer>
        <p>联系邮箱:example@email.com</p>
    </footer>
</body>
</html>

基础CSS样式

styles.css中定义样式,从布局到细节逐步完善:

/* 全局样式 */
body {
    font-family: 'Arial', sans-serif;
    line-height: 1.6;
    margin: 0;
    padding: 0;
    color: #333;
    background-color: #f4f4f4;
}

/* 页眉样式 */
header {
    background: #35424a;
    color: #ffffff;
    padding: 20px 0;
    text-align: center;
}

header h1 {
    margin: 0;
}

/* 主要内容区 */
main {
    padding: 20px;
    max-width: 800px;
    margin: 0 auto;
}

section {
    margin-bottom: 20px;
    background: #ffffff;
    padding: 20px;
    border-radius: 5px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

h2 {
    color: #35424a;
    border-bottom: 2px solid #e8491d;
    padding-bottom: 5px;
}

/* 列表样式 */
ul {
    list-style-type: none;
    padding: 0;
}

ul li {
    padding: 5px 0;
}

/* 页脚样式 */
footer {
    text-align: center;
    padding: 10px;
    background: #35424a;
    color: #ffffff;
    position: fixed;
    bottom: 0;
    width: 100%;
}

响应式设计

添加媒体查询适配移动设备:

@media (max-width: 600px) {
    header h1 {
        font-size: 24px;
    }

    main {
        padding: 10px;
    }

    section {
        padding: 15px;
    }
}

交互效果增强

通过CSS悬停效果提升用户体验:

header {
    transition: background 0.3s ease;
}

header:hover {
    background: #e8491d;
}

ul li:hover {
    color: #e8491d;
    cursor: default;
}

进阶布局技巧

使用Flexbox或Grid优化布局:

/* Flexbox示例:技能列表横向排列 */
.skills ul {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.skills li {
    background: #e8491d;
    color: white;
    padding: 5px 10px;
    border-radius: 3px;
}

部署与扩展

  • 将项目上传至GitHub Pages或Netlify免费托管
  • 后续可扩展添加项目展示区、博客链接等模块
  • 学习使用CSS变量(如--primary-color: #e8491d;)统一主题色

通过以上步骤,逐步构建一个结构清晰、样式美观的静态个人主页,适合作为CSS入门练手项目。

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值