<!DOCTYPE html> <html> <head> <title>我的第一个网页</title> <style> /* CSS样式 */ body { font-family: Arial; text-align: center; } .button { background: blue; color: white; padding: 10px 20px; border: none; } </style> </head> <body> <h1>欢迎访问我的网站!</h1> <p>这是一个简单的网页示例。</p > <button class="button" onclick="alert('你好!')">点击我</button> </body> </html>


这段HTML代码创建了一个简单的网页,包含、段落和按钮。分析如下: 1. 文档类型声明正确使用HTML5标准 2. 基本结构完整(head/body标签) 3. 内联CSS样式定义了全局字体和按钮样式 4. 按钮绑定了简单的JavaScript点击事件 优化建议: - 按钮样式可增加:hover状态增强交互性 - 考虑将CSS移至外部文件便于维护 - 添加viewport meta标签适配移动设备 示例改进: ```css .button:hover { background: darkblue; cursor: pointer; } ``` ```html <meta name="viewport" content="width=device-width, initial-scale=1"> ``` 我在以往的开发过程中,碰到过以下几点需要格外小心处理的地方: 1. 内联JavaScript事件处理(onclick)不利于维护,建议使用addEventListener 2. 颜色值建议使用HEX或RGB格式而非颜色名称,保证浏览器兼容性 3. 自闭合标签(如<meta>)在HTML5中不需要斜杠,保持语法一致性 [2025-08-10 23:55:26 | AI写代码神器 | 219点数解答]
相关提问
- <!DOCTYPE html> <html> <head> <title>我的第一个网页</title> <style> /* CSS样式 */ body { font-family: Arial; text-align: center; } .button { background: blue; color: white; padding: 10px 20px; border: none; } </style> </head> <body> <h1>欢迎访问我的网站!</h1> <p>这是一个简单的网页示例。</p > <button class="button" onclick="alert('你好!')">点击我</button> </body> </html> (219点数解答 | 2025-08-10 23:55:26)92
- <!DOCTYPE html> <html> <head> <title>手机网页</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <style> body { font-family: Arial; text-align: center; padding: 20px; } button { padding: 10px 20px; font-size: 16px; } </style> </head> <body> <h1>手机网页示例</h1> <p id="demo">点击下方按钮试试</p> <button onclick="showMessage()">点击我</button> <script> function showMessage() { document.getElementById("demo").innerHTML(618点数解答 | 2025-07-13 23:54:21)79
- <!DOCTYPE html> <html> <head> <title>手机网页</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <style> body { font-family: Arial; text-align: center; padding: 20px; } button { padding: 10px 20px; font-size: 16px; } </style> </head> <body> <h1>手机网页示例</h1> <p id="demo">点击下方按钮试试</p> <button onclick="showMessage()">点击我</button> <script> function showMessage() { document.getElementById("demo").innerHTML(332点数解答 | 2025-07-13 23:57:24)84
- <!DOCTYPE html> <html> <head> <style> body { font-family: 'Arial', sans-serif; background: #fff5f7; padding: 20px; } .container { max-width: 600px; margin: 0 auto; background: white; border-radius: 15px; padding: 25px; box-shadow: 0 4px 10px rgba(0,0,0,0.1); } .title { color: #ff3366; font-size: 24px; text-align: center; padding: 15px; background: #fff0f3; border-radius: 10px; margin-bottom: 20px; } .tip-card { background: #f8f9fa; border-left: 4px solid #f(308点数解答 | 2025-02-26 23:11:57)226
- <!DOCTYPE html> <html> <head> <style> body { font-family: Arial, sans-serif; background: #f5f5f5; } .container { max-width: 500px; margin: 20px auto; padding: 20px; background: white; border-radius: 10px; box-shadow: 0 0 10px rgba(0,0,0,0.1); } .header { text-align: center; font-size: 24px; font-weight: bold; margin-bottom: 20px; color: #333; } .flavor { display: flex; justify-content: space-between; margin: 15px 0; padding: 10px; border-bottom: 1px dashed #ee(1102点数解答 | 2025-06-23 18:32:52)89
- <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>SC1030皮卡车后驱动桥设计论文</title> <style> body { font-family: SimSun; line-height: 1.5; } h1 { text-align: center; font-size: 22pt; } h2 { font-size: 16pt; margin-top: 20pt; } table { border-collapse: collapse; width: 100%; margin: 20px 0; } th, td { border: 1px solid #000; padding: 8px; text-align: left; } img { max-width: 100%; display: block; margin: 10px auto; } </style> </head> <body> <h1>SC1030皮卡车后驱动桥设计</h1> <h2>摘要</h2> (111点数解答 | 2025-03-03 12:53:25)185
- <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>赵庆喜的页面</title> <style> body { font-family: Arial, sans-serif; text-align: center; margin-top: 50px; } button { padding: 10px 20px; font-size: 16px; cursor: pointer; } </style> </head> <body> <h1>欢迎来到赵庆喜的页面</h1> <button onclick=(143点数解答 | 2025-03-23 20:50:38)137
- <!DOCTYPE html> <html> <head> <style> body { background: #fff5f7; font-family: "Microsoft YaHei", sans-serif; padding: 20px; } .container { max-width: 600px; margin: 0 auto; background: white; border-radius: 15px; padding: 25px; box-shadow: 0 4px 8px rgba(0,0,0,0.1); } .title { color: #ff4b6e; font-size: 24px; font-weight: bold; margin-bottom: 15px; text-align: center; } .subtitle { color: #666; font-size: 14px; margin-bottom: 20px; text-align: center; } .(338点数解答 | 2025-02-26 22:59:16)248
- <!--弹窗代码开始--> <script src="https://cdn.ioszn.com/js/sweetalert.min.js"></script> <style> /* center align buttons in sweetalert dialog */ .swal-footer { text-align: center; } /* add your custom button styles here */ .custom-swal-button { font-size: 14px; padding: 10px 20px; border-radius: 5px; } /* style for the "确认密码" button */ .swal-button--confirm { background-color: cornflowerblue; /* change to your desired color */ color: white; /* text color */ } /* style for the "复制公众号" butt(625点数解答 | 2024-08-24 22:43:19)184
- <!DOCTYPE html> <html> <head> <style> body { font-family: Arial, sans-serif; max-width: 800px; margin: auto; border: 2px solid #e0e0e0; padding: 20px } .header { text-align: center; border-bottom: 2px solid #c00; padding-bottom: 10px } .section { margin: 15px 0 } table { width: 100%; border-collapse: collapse } th, td { border: 1px solid #ddd; padding: 8px; text-align: left } .diagnosis { background: #fff8e1; padding: 15px; border-left: 4px solid #ffc107 } .signatur(223点数解答 | 2025-06-10 13:32:12)90
- <!DOCTYPE html> <html> <head> <title>PCSP金属盘-AR泡沫玻璃板安装仿真</title> <style> body { font-family: Arial, sans-serif; margin: 20px; } .diagram { background: #f5f5f5; padding: 15px; margin: 10px 0; border-radius: 5px; } pre { background: #eee; padding: 10px; overflow-x: auto; } table { border-collapse: collapse; width: 100%; margin: 15px 0; } th, td { border: 1px solid #ddd; padding: 8px; text-align: left; } button { padding: 8px 12px; margin: 5px(1571点数解答 | 2025-06-16 21:26:05)97
- <!DOCTYPE html> <html> <head> <title>简易计时器</title> <style> body { font-family: Arial, sans-serif; text-align: center; margin-top: 50px; } #display { font-size: 48px; margin: 20px; } button { padding: 10px 20px; font-size: 16px; margin: 5px; cursor: pointer; } </style> </head> <body> <h1>计时器</h1> <div id="display">00:00:00<(213点数解答 | 2025-04-28 22:10:35)129