一、HTML(alt+p强制ai生成)

  • 超文本,标记语言
    • 不区分大小写
    • 属性值可以使用单引号也可以使用双引号
    • 不严格规范
  • 页面原型是指由产品经理制作用来提示学些的

1.常见标签

  • 整体架构

    • <html>
      <head>
        <title>HTML-CSS快速入门</title>
      </head>
      <body>
        <h1>黑马程序</h1>
         <h1>黑马程序</h1>
      </body>
      </html>
      
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12

      * **h1-h6标签**

      * **段落标签**

      * **a标签**

      * ~~~html
      <a href="https://www.cctv.com/">央视网</a>
      href 链接地址
      target _blank新窗口打开
      _self本窗口打开
  • span标签—表示没有语意的标签

  • 1
    <br>换行标签
  • p标签

    • <p>段落标签
          <p>
              段落标签
          </p>
      
      1
      2
      3
      4
      5

      * **b标签(strong标签与之相同)**

      * ~~~html
      加粗展示文本内容

2.视频音频标签

  • 1
    <video src="" controls autoplay width="500"></video>
  • 1
    2
    3
    4
    5
    6
    7
    controls表示播放控件

    autoplay自动播放

    width="500"
    单位可以为px像素
    也可以是%表示百分比
  • 1
    <audio src="" controls autoplay width="500"></audio>

3.图片标签

  • 1
    <img src="https://chuanchua.oss-cn-beijing.aliyuncs.com/markdown/image-20251004214726635.png" alt="">
  • 1
    2
    3
    4
    5
    6
    7
    8
    9
    src属性
    绝对与相对路径,注意使用在线服务器打开
    绝对路径
    绝对网络路径
    绝对磁盘路径
    width属性
    设置宽度等等
    hight属性

4.表单标签

  • 网页中用来收集信息,提交信息

  • 主标签-

    • 表单项

      • <input>
            1.属性许多,通过属性修改不同格式
            2.必须设置name属性,用来注明提交数据id
            3.hidden的信息也会提交
            4.属性设置大概如下
                <input type="hidden" name="token" value="123456">
            5.有关选择的类型需要加入value属性
            
        
        1
        2
        3
        4
        5
        6
        7
        8
        9
        10
        11
        12
        13
        14
        15

        * | **type**取值**** | **描述** | **补充** |
        | ---------------------------- | ---------------------------------------- | --------------------------- |
        | **text** | **默认值,定义单行的输入字段** | **placeholder用作设置提示** |
        | **password** | **定义密码字段** | |
        | **radio** | **定义单选按钮** | |
        | **checkbox** | **定义复选框** | |
        | **file** | **定义文件上传按钮** | |
        | **date/time/datetime-local** | **定义日期/时间/日期时间** | |
        | **hidden** | **定义隐藏域** | |
        | **submit / reset / button** | **定义提交按钮 / 重置按钮 / 可点击按钮** | |

        * ~~~html
        <select>
        定义下拉列表,<option>定义选项
      • <textarea>
            文本输入框
        
        1
        2
        3
        4
        5
        6
        7
        8
        9
        10

        * ~~~html
        <label>
        优化用户体验
        * 可以将文本内容一体化
        1.简单写法,直接包裹
        <label><input type="radio" name="gender" value="男">男</label>
        2.目标写法
        <label for="username1">用户名:</label> //for对应的是id属性的值
        <input type="text" name="username" id="username1" placeholder="请输入用户名">
      • <inpiut type="submit" value="提交">
            //表单要是想要提交信息,必须设置submit
             submit / reset / button通常配合js使用  
        
        1
        2
        3
        4
        5
        6

        * **核心属性**

        * ~~~html
        action
        <form action="https://www.baidu.com/" method="get"> //目标地址,百度官网
      • method
            <form action="https://www.baidu.com/" method="get">  //进行传输数据的方式 get与post
                
        
        1
        2
        3
        4
        5
        6
        7
        8
        9
        10
        11
        12
        13
        14
        15
        16
        17
        18
        19
        20
        21
        22
        23
        24
        25
        26
        27
        28
        29
        30



        ### 5.表格标签

        * ~~~html
        <table> //表格
        <thead> //定义表头
        <tr> //定义一行
        <th>姓名</th> //定义每一格
        <th>年龄</th>
        <th>性别</th>
        <th>爱好</th>
        </tr>
        </thead>
        <tbody> //定义表格体
        <tr>
        <td>张三</td>
        <td>18</td>
        <td>男</td>
        <td>篮球、足球</td>
        </tr>
        <tr> //一行
        <td>李四</td>
        <td>19</td>
        <td>女</td>
        <td>足球、跑步</td>
        </tr>
        </tbody>
        </table>
  • 定义表格整体
    用于定义表格头部(可选)
    定义表格中的主体部分(可选)
    表格的行,可以包裹多个
    表格单元格(普通),可以包裹内容;如果是表头单元格,可以替换为

    二、CSS

    1.引入css方式

    • 行内样式

      • <h1 style="color: red;">黑马程序</h1>
        
        1
        2
        3
        4
        5
        6
        7
        8
        9

        * **内部样式**

        * ~~~html
        <style>
        h1{
        color: red;
        }
        </style>
      • 一般在head标签内部定义一个style标签

      • 缺点定义太广

    • 外部样式

      • <link rel="stylesheet" href="./CSS/style.css">
        
        1
        2
        3
        4
        5
        6
        7
        8
        9
        10
        11

        * **一般在head标签,通过link标签引入外部css文件**

        * **复用性最好**

        ### 2.颜色描述方式

        ~~~html
        h1{
        color: rgb(255, 0, 0);//属性,设置文本颜色
        }
    • 关键字

      • blue green blue
        
        1
        2
        3
        4
        5
        6
        7

        * **rgb方法**

        * ~~~html
        红绿蓝三原色,取值:0-255
        rgb(r,g,b)

    • rgba方法

      • 红绿蓝三原色,a表示透明度,取值:0-1
        rgba(r,g,b,a)
        
        1
        2
        3
        4
        5
        6
        7

        * **十六进制方法**

        * ~~~html
        #rrggbb
        #开头,将数字转换成十六进制表示

      • 也有简写方式

    3.样式选择器

    • 三种方式id优先

    • image-20251012144030583

    • 元素选择器

      •     <style>
            h1{
                color: rgb(255, 0, 0);
            }
          </style>
        
        <h1>黑马程序</h1>
        <h1>黑马程序</h1>
        
        1
        2
        3
        4
        5
        6
        7
        8
        9
        10
        11
        12
        13

        * **类选择器**

        * **先为标签设置类属性,然后在style中设置**

        * ~~~html
        <style>
        .title{
        color: rgb(0, 0, 255);
        }
        </style>

        <h1 class="title">黑马程序</h1>
    • id选择器

      • 先为标签设置id属性,然后在style中设置

      • <style>
        #title{
                color: rgb(0, 255, 0);
            }
        </style>
        
        <h1 class="title" id="title">黑马程序</h1>
        
        1
        2
        3
        4
        5
        6
        7

        ### 4.为段落设置样式

        * ~~~html
        p{
        line-height: 30px;
        }
    • 为段落添加空格

      • 1.实体字符
            <p>&nbsp;&nbsp;&nbsp;&nbsp;是一个专业的IT培训机构,<br>专注于为学生提供专业的IT课程。</p>  
        
        1
        2
        3
        4
        5
        6

        * ~~~html
        p{
        line-height: 30px;
        text-indent: 2em;//首行缩进俩个字符
        }

    5.盒子模型

    • 将整体的body代码放入div标签,然后对对应的容器div设置css样式

    • 具体

      • 一般有如下俩个标签
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      25
      26
      27
      28
      1.<div>标签
      一行只显示一个(独占一行)
      宽度默认是父元素的宽度,高度默认由内容撑开
      可以设置宽高(width、height)

      2.<span>标签
      一行可以显示多个
      宽度和高度默认由内容撑开
      不可以设置宽高(width、height)

      3.具体属性
      width: 500px;
      height: 300px; /* 长度与高度,默认由内容撑开 */
      background-color: rgb(255, 0, 0); 背景色
      padding: 20px; 内边距
      margin: 50px; 外边距
      border: 10px solid rgb(0, 0, 255); 边框

      box-sizing: border-box;content-box (默认是内容)设置展开方式


      4.关于属性的值
      一个值 上下左右
      两个值 第一个上下,第二个左右
      三个值 最后一个是下面
      四个值 遵循顺时针方向
      auto 有时候可以设置为居中
      具体设置某一边可以加入-left等等

    6.flex弹性布局

    • 一种一维布局方式

    • 创建方法

      • 针对于父元素设置,即父容器
        1.设置容器
           <div id="container">
             <div id="div2">
                <div class="item"></div>
                <div class="item"></div>
                <div class="item"></div>
              </div>
          </div>
        2.css代码
            #container{
                width: 600px;
                height: 600px;
                background-color: rgb(218, 199, 199);
                display: flex;             //开启弹性布局
                flex-direction: column;        //设置主轴,默认为横轴
                justify-content: center;    //具体值见下表
                align-items: center;
            }
        
      • flex-start 从头开始排列
        flex-end 从尾部开始排列
        center 在主轴居中对齐
        space-around 平分剩余空间
        space-between 先两边贴边,再平分剩余空间
    文章作者: 十七.
    文章链接: https://zc-18.github.io/2025/05/22/Javaweb_05/
    版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来源 十七.!