web前端开发技术课堂笔记 02

HTM5的优势
  1. 解决了跨浏览器问题

  2. 新增了多个新特性

  3. 用户优先原则

  4. 化繁为简的优势

    书写代码注意

    1.缩进时用Tab键缩进,不要用空格

    2.所有标签用<>包裹,成对出现。如......

<!DOCTYPE html>//告诉浏览器我要按HTM5的结构写代码
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>实时系统时间</title>
    <style>
        /* 页面整体样式 */
        body {
            font-family: "Microsoft YaHei", Arial, sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
            background-color: #f0f2f5;
        }

        /* 时间显示容器 */
        .time-container {
            background-color: #ffffff;
            padding: 40px 60px;
            border-radius: 12px;
            box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
            text-align: center;
        }

        /* 时间文本样式 */
        #current-time {
            font-size: 3rem;
            color: #1a73e8;
            font-weight: bold;
            letter-spacing: 2px;
        }

        /* 响应式适配 */
        @media (max-width: 600px) {
            #current-time {
                font-size: 2rem;
            }
            .time-container {
                padding: 20px 30px;
            }
        }
    </style>
</head>
<body>
    <div class="time-container">
        <div id="current-time"></div>
    </div>

    <script>
        // 获取显示时间的DOM元素
        const timeElement = document.getElementById('current-time');

        // 格式化时间函数:补零操作(确保个位数显示为两位,如 9 → 09)
        function formatNumber(num) {
            return num.toString().padStart(2, '0');
        }

        // 更新时间的核心函数
        function updateTime() {
            // 获取当前系统时间
            const now = new Date();
            
            // 提取年月日时分秒
            const year = now.getFullYear(); // 年(4位)
            const month = formatNumber(now.getMonth() + 1); // 月(注意月份从0开始,需+1)
            const day = formatNumber(now.getDate()); // 日
            const hour = formatNumber(now.getHours()); // 时
            const minute = formatNumber(now.getMinutes()); // 分
            const second = formatNumber(now.getSeconds()); // 秒

            // 拼接成指定格式的时间字符串
            const timeStr = `${year}年${month}月${day}日 ${hour}:${minute}:${second}`;
            
            // 将时间显示到页面上
            timeElement.textContent = timeStr;
        }

        // 初始化:立即执行一次,避免页面加载后有延迟
        updateTime();

        // 设置定时器:每1000毫秒(1秒)更新一次时间,实现实时效果
        setInterval(updateTime, 1000);
    </script>
</body>
</html>
代码架构

​ html

​ 1.head 2.body

(1)meat title style (2) div cript

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<!--网页的标题,出现在选项卡上-->
		<title>我的第一个主页</title>
		
	</head>
	<body>
		<!--标题,1~6,标题一最大,标题六最小-->
		<h1>云课堂上线了</h1>
		<!--段落-->
		<p>更新时间:2026年3月4日00时00分 来源:刘静</p>
		<!--单标签,插入一条水平线-->
		<hr />
		<p>XX云课堂是在线教育平台,可以实现晚上在家学习、在线直播教学、实时互动辅导等多种功能,专注于网页、平面、UI设计以及Web前端的培训。</p>
	</body>
</html>

posted @ 2026-03-14 13:13  柒月份  阅读(19)  评论(0)    收藏  举报