Skip to main content

web 基础

  • <p> 标签
  • main 标签: 用于表示 HTML 的 body 中主要内容, 在其中的内容在该 document 中需要是唯一的.
  • img 标签: 用于展示图片
  • 若一个 element 不带 closing tag, 这种叫做 void element.
  • 在 element 的 opening tag 中写的特殊文本, 称为 attributes, 用于控制 element 的行为.
  • a 标签: 用于添加 link, 在 a 标签的 opening 和 closing tag 间添加 link 对应的文本, 比如 <a href="https://www.xxx.com">My link</a>.
    • 此外, a 标签中还可以添加诸如图片等内容.
  • section element: 用于定义一个文档中的各个部分, 比如 chapters, headers, footers 等. 对 SEO 和访问均有帮助.
    • 在 section 中可以添加子 section
  • ul: 无序列表, 在其中可以添加列表元素 li
  • figure: 用于给 image 添加标题, 方法就是将 img 包裹到 figure 中, 然后添加一个 figcaption element.
  • em: 用于强调(Emphasize)一段文本, 展示为斜体
  • ol: 有序列表, 其中 li 前面会自动添加序号
  • strong: 用于表示"重要", 展示为加粗
  • form: 用于输入表单
    • action attribute: 表示 form 的最终提交动作目的地.
    • input element: 在 form 中用于表示一个输入
      • type attribute: 在 input 中表示此 input 的类型, 比如 text(文本输入), ratio(单选), checkbox(勾选)
        • 若想在 ratio 上添加文本, 需要使用 label 将此 ratio input 包裹起来, 这样 ratio input 就有了展示文本.
        • 若想多个 ratio input 能够互斥选中(或多个 input 可成组), 则这些 input 的 name 必须一样.
        • value attribute: 表示 ratio input 的值(如果不添加, 则提交时, 只能获得这组 ratio input 是 on 还是 off), 添加后, 就可以知道选中的是哪个值了.
        • 可以使用 fieldset 包裹几个 ratio input, 让这些 ratio input 成为一个组.
        • fieldset 中可以包裹 legend, 用于表示该 fieldset 的标题.
        • 若设置了 input 的 id, 则可使用 for attribute 关联一个 input 的 label text, 如 <label for="breakfast">Breakfast</label>, 这样可以将 label 和 input 分开, 而非包裹.
        • checked attribute: 用于表示 ratio/checkbox 是否是被选中的.
      • name attribute: 在 input 中表示此 input 的名字, 这样可以通过此名字获取该 input 的数据
      • placeholder attribute: 在 input 中表示此 input 的占位文本
      • required attribute: 表示 input 是必填的
    • button element: 在 form 中添加后, 可以作为提交按钮
      • submit attriubte: 表示此 button 是一个提交按钮
  • id attribute: 用于表示一个 HTML element 的识别名字.
  • footer element: 表示作为 document 的 footer 的元素组.
  • body element: 能够被可视化渲染的 HTML 部分都需要在 body 中.
  • head element: 包含 HTML 的各种元数据(title, description)以及 script, css 等.
    • meta element: 在 head 中提供各种元数据
      • charset attribute: 表示 html 的 charset.
  • <!DOCTYPE html> declaration: 任何 HTML 文档都应以此特殊字符串开头, 用于告知浏览器这个 HTML 是 HTML5 的.
  • html element: 用于包裹 head, footer, body.
    • lang attribute: 表示 html 语言, 比如 <html lang="en">.