宜兰县网站建设_网站建设公司_加载速度优化_seo优化
2026/1/12 3:45:09 网站建设 项目流程

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="style.css"> </head> <body> <header> <h1>我的第一个网页</h1> </header> <main> <button id="actionBtn">点击交互</button> <p id="outputText">默认文本</p> </main> <script src="script.js"></script> </body> </html>

https://www.zhihu.com/zvideo/1993886892358391662/
https://www.zhihu.com/zvideo/1993886892358391662
https://www.zhihu.com/zvideo/1993886892782018656/
https://www.zhihu.com/zvideo/1993886892782018656
https://www.zhihu.com/zvideo/1993886890127029482/
https://www.zhihu.com/zvideo/1993886890127029482
https://www.zhihu.com/zvideo/1993886886121447565/
https://www.zhihu.com/zvideo/1993886886121447565
https://www.zhihu.com/zvideo/1993886887132296332/
https://www.zhihu.com/zvideo/1993886887132296332
https://www.zhihu.com/zvideo/1993886886859650936/
https://www.zhihu.com/zvideo/1993886886859650936
https://www.zhihu.com/zvideo/1993886886037570757/
https://www.zhihu.com/zvideo/1993886886037570757
https://www.zhihu.com/zvideo/1993886881407050866/
https://www.zhihu.com/zvideo/1993886881407050866
https://www.zhihu.com/zvideo/1993886880119420006/
https://www.zhihu.com/zvideo/1993886880119420006
https://www.zhihu.com/zvideo/1993886879884537914/
https://www.zhihu.com/zvideo/1993886879884537914
https://www.zhihu.com/zvideo/1993886879024709674/
https://www.zhihu.com/zvideo/1993886879024709674
https://www.zhihu.com/zvideo/1993886875497293411/
https://www.zhihu.com/zvideo/1993886875497293411
https://www.zhihu.com/zvideo/1993886874440320311/
https://www.zhihu.com/zvideo/1993886874440320311
https://www.zhihu.com/zvideo/1993886867507146794/
https://www.zhihu.com/zvideo/1993886867507146794
https://www.zhihu.com/zvideo/1993886860754314650/
https://www.zhihu.com/zvideo/1993886860754314650
https://www.zhihu.com/zvideo/1993886858418069813/
https://www.zhihu.com/zvideo/1993886858418069813

CSS 基础样式

/* 全局样式 */ body { font-family: 'Arial', sans-serif; line-height: 1.6; margin: 0; padding: 20px; background-color: #f4f4f4; } header { background: #35424a; color: white; padding: 10px 0; text-align: center; } button { background: #e8491d; color: white; border: none; padding: 10px 20px; cursor: pointer; } button:hover { background: #333; }

JavaScript 交互逻辑

document.getElementById('actionBtn').addEventListener('click', function() { const outputElement = document.getElementById('outputText'); outputElement.textContent = '按钮已点击!'; outputElement.style.color = 'green'; });

实战项目:简易待办清单

<!-- HTML部分 --> <div class="todo-container"> <input type="text" id="todoInput" placeholder="输入任务..."> <button id="addBtn">添加</button> <ul id="todoList"></ul> </div>
/* CSS部分 */ .todo-container { max-width: 500px; margin: 20px auto; } #todoInput { width: 70%; padding: 8px; } ul { list-style-type: none; padding: 0; } li { background: white; margin: 5px 0; padding: 10px; border-left: 3px solid #e8491d; }
// JavaScript部分 document.getElementById('addBtn').addEventListener('click', function() { const input = document.getElementById('todoInput'); const list = document.getElementById('todoList'); if (input.value.trim() !== '') { const li = document.createElement('li'); li.textContent = input.value; list.appendChild(li); input.value = ''; } });

学习要点说明

  • HTML:定义网页结构,使用语义化标签(如<header><main>
  • CSS:控制视觉表现,注意选择器优先级和盒模型
  • JavaScript:通过DOM操作实现动态交互,事件监听是核心机制

通过修改上述代码中的颜色、布局或添加新功能(如删除任务按钮)可进一步练习。

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询