search
HomeWeb Front-endHTML Tutorial第2 章 基本格式_html/css_WEB-ITnose

学习要点:

1.HTML5 文档结构
2.文档结构解析
3.元素标签探讨

主讲教师:李炎恢

  本章主要先从 HTML5 的文档结构谈起。 这些基础元素确定了 HTML 文档的轮廓以及浏览器的初始环境。几乎所有页面都必须首先键入这些元素。

一.HTML5 文档结构
1.第一步:打开 Sublime Text 3,打开指定文件夹;
2.第二步:保存 index.html 文件到磁盘中,.html 是网页后缀;
3.第三步:开始编写 HTML5 的基本格式。

<!DOCTYPE html>                                  //文档类型声明<html lang="zh-cn">                              //表示 HTML 文档开始    <head>                                       //包含文档元数据开始        <meta charset="utf-8">                   //声明字符编码        <title>基本结构</title>                   //设置文档标题    </head>                                      //包含文档元数据结束    <body>                                       //表示 HTML 文档内容        <a href="http://www.baidu.com">百度</a>  //一个超链接元素(标签)    </body>                                      //表示 HTML</html>                                          //表示 HTML 文档结束

 

二.文档结构解析
1.Doctype
  文档类型声明(Document Type Declaration,也称 Doctype)。它主要告诉浏览器所查看的文件类型。 在以往的 HTML4.01 和XHTML1.0 中, 它表示具体的 HTML 版本和风格。而如今 HTML5 不需要表示版本和风格了。

<!DOCTYPE html>       //不分区大小写

2.html 元素
  首先,元素就是标签的意思,html 元素即 html 标签。html 元素是文档开始和结尾的元素。它是一个双标签,头尾呼应,包含内容。这个元素有一个属性和值:lang="zh-cn",表示文档采用语言为:简体中文。

<html lang="zh-cn">   //如果是英文则为 en

3.head 元素
  用来包含元数据内容,元数据包括:

<head>...</head>     //这些信息在页面不可见

4.meta 元素
  这个元素用来提供关于文档的信息,起始结构有一个属性为:charset="utf8"。表示告诉浏览器页面采用的什么编码,一般来说我们就用 utf8。当然,文件保存的时候也是utf8,而浏览器也设置 utf8 即可正确显示中文。

<meta charset="utf-8">    //除了设置编码,还有别的

5.title 元素
  这个元素很简单,顾名思义:设置浏览器左上角的标题。

<title>基本结构</title>

6.body 元素
  用来包含文档内容的元素,也就是浏览器可见区域部分。所有的可见内容,都应该在这个元素内部进行添加。

<body>...</body>

7.a 元素
  一个超链接,后面会详细探讨。

<a href="http://www.baidu.com">百度</a>

 

三.元素标签探讨
  HTML 是一种标记语言,刚才的结构我们已经详细探讨过。这里,我们再剖析一下这些“标记”或者叫“标签”,书面上经常称作为“元素”的东西是怎么构成的。

1.元素
  元素就是一组告诉浏览器如何处理一些内容的标签。每个元素都有一个关键字,比如

、<meta>都是元素。不同的标签名称代表不同的意义,后面将会涉及到段落标签、文本标签、链接标签、图片标签等。<br>元素一般分为两种:单标签(空元素)和双标签。单标签一般用于声明或者插入某个元素,比如声明字符编码就用<meta>,插入图片就用<img alt="第2 章 基本格式_html/css_WEB-ITnose" >;双标签一般用于设置一段区域的内容,将其包含起来,比如段落<p>...</p>。 <p><strong>2.属性和值</strong><br>  元素除了有单双之分, 元素的内部还可以设置属性和值。 这些属性值用来改变元素某些方面的行为。比如超链接:<a>中的href 属性,里面替换网址即可链接到不同的网站。当然一个元素里面可以设置多个属性,甚至自定义属性。</a></p> <p> </p> <p class="sycode"></p> <p class="sycode"></p> <p class="sycode"> </p> <p class="sycode"></p> <p class="sycode"></p> <p class="sycode"> </p> <p class="sycode"></p> <p class="sycode"></p>
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Difficulty in updating caching of official account web pages: How to avoid the old cache affecting the user experience after version update?Difficulty in updating caching of official account web pages: How to avoid the old cache affecting the user experience after version update?Mar 04, 2025 pm 12:32 PM

The official account web page update cache, this thing is simple and simple, and it is complicated enough to drink a pot of it. You worked hard to update the official account article, but the user still opened the old version. Who can bear the taste? In this article, let’s take a look at the twists and turns behind this and how to solve this problem gracefully. After reading it, you can easily deal with various caching problems, allowing your users to always experience the freshest content. Let’s talk about the basics first. To put it bluntly, in order to improve access speed, the browser or server stores some static resources (such as pictures, CSS, JS) or page content. Next time you access it, you can directly retrieve it from the cache without having to download it again, and it is naturally fast. But this thing is also a double-edged sword. The new version is online,

How do I use HTML5 form validation attributes to validate user input?How do I use HTML5 form validation attributes to validate user input?Mar 17, 2025 pm 12:27 PM

The article discusses using HTML5 form validation attributes like required, pattern, min, max, and length limits to validate user input directly in the browser.

What are the best practices for cross-browser compatibility in HTML5?What are the best practices for cross-browser compatibility in HTML5?Mar 17, 2025 pm 12:20 PM

Article discusses best practices for ensuring HTML5 cross-browser compatibility, focusing on feature detection, progressive enhancement, and testing methods.

How to efficiently add stroke effects to PNG images on web pages?How to efficiently add stroke effects to PNG images on web pages?Mar 04, 2025 pm 02:39 PM

This article demonstrates efficient PNG border addition to webpages using CSS. It argues that CSS offers superior performance compared to JavaScript or libraries, detailing how to adjust border width, style, and color for subtle or prominent effect

What is the purpose of the <datalist> element?What is the purpose of the <datalist> element?Mar 21, 2025 pm 12:33 PM

The article discusses the HTML <datalist> element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

What is the purpose of the <progress> element?What is the purpose of the <progress> element?Mar 21, 2025 pm 12:34 PM

The article discusses the HTML <progress> element, its purpose, styling, and differences from the <meter> element. The main focus is on using <progress> for task completion and <meter> for stati

How do I use the HTML5 <time> element to represent dates and times semantically?How do I use the HTML5 <time> element to represent dates and times semantically?Mar 12, 2025 pm 04:05 PM

This article explains the HTML5 <time> element for semantic date/time representation. It emphasizes the importance of the datetime attribute for machine readability (ISO 8601 format) alongside human-readable text, boosting accessibilit

What is the purpose of the <meter> element?What is the purpose of the <meter> element?Mar 21, 2025 pm 12:35 PM

The article discusses the HTML <meter> element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates <meter> from <progress> and ex

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),