Home > Web Front-end > H5 Tutorial > A detailed introduction to HTML5-creating HTML documents

A detailed introduction to HTML5-creating HTML documents

黄舟
Release: 2017-03-11 16:52:30
Original
1567 people have browsed it

One of the major changes in HTML5 is: Separating the semantics of an element from the impact of the element on the rendering results of its content. In principle, this makes sense. HTML elements are responsible for the structure and meaning of the document content, and the presentation of the content is controlled by CSS styles applied to the elements. The following introduces the most basic HTML elements: document elements and metadata elements.

1. Build the basic document structure

There are only 4 document elements: DOCTYPE element, html element, head element, and body element.

1. DOCTYPE element

Every HTML document must start with a DOCTYPE element. It tells the browser two things: first, that it is dealing with an HTML document; and second, the version of HTML used to mark up the document's content.
Note, the DTD required in HTML4 is no longer used in HTML5!

  • If the web page code contains the DOCTYPE element, the browser will parse it according to the standards you declare;

  • If you do not add the DOCTYPE element, the browser will Put the web page into quirks mode, there will be a certain difference between the two! !

<!-- HTML4 --><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
            "http://www.w3.org/TR/html4/strict.dtd">
            <!-- HTML5 --><!DOCTYPE HTML>
Copy after login

2. Other elements

<!DOCTYPE HTML><html>
    <head>
        <title>title</title>
    </head>
    <body>
        文档内容    </body></html>
Copy after login

It should be noted that there must be a title element in the head element!

2. Use metadata elements to describe documents

Metadata elements should be placed in the head element.

1. Set the document title: title element

2. Set the parsing base for relative URLs

The base element can be used to set a base URL for relative links in HTML documents Analyze on this basis. The base element also sets how the link opens when the user clicks it, and how the browser reacts when the form is submitted (described in Chapter 12, Forms).

<!doctype html><html lang="en"><head>
    <meta charset="UTF-8">
    <title>Base Test</title>
    <!-- 指定相对URL的基准URL -->
    <base href="http://avatar.csdn.net">
    <!-- 指定链接打开方式为:当前页面 -->
    <base target="_self"></head><body>
    <!-- 图片地址:http://www.php.cn/ -->
    <img src="/1/4/A/1_ligang2585116.jpg" alt="奋飞">
    <a href="http://http://www.php.cn/">PHP中文网</a></body></html>
Copy after login

Note: If you do not specify a base URL, the browser will identify the URL of the current document as the parsing base for all relative URLs.

3. Use metadata to describe the document

The meta element can be used to define various metadata of the document; each meta element can only be used for one purpose.
(1) Specify the name/value metadata pair
You need to use its name and content attributes. 5 predefined metadata names are provided.

##application nameThe name of the web application system to which the current page belongsauthorThe author name of the current pagedescriptionDescription of the current pagegeneratorThe name of the software used to generate HTMLkeywordsA batch of comma-separated strings used to describe the content of the page
Metadata nameDescription

Description: Tell the browser how to classify and grade the content, In the past, the main method was to use keywords metadata. It is now devalued due to its misuse to create the illusion of page content and relevance. (2) Meta is widely used

<!-- 文档内容的字符编码 -->
<meta charset="UTF-8">
<meta http-equiv="content-type" content="text/html charset=UTF-8">
<!-- 5s后刷新当前页面 -->
<meta http-equiv="refresh" content="5">
<!-- 5s后跳转到MyBlog -->
<meta http-equiv="refresh" content="5; http://www.php.cn/">
Copy after login

4. Define CSS styles

The style element is used to define the CSS style embedded in the HTML document, and the link element is used to import the CSS style in the external style sheet. style.

(1) Specify the media to which the style applies

media attribute can be used to indicate under what circumstances the document should use the style defined in this element.

DeviceDescription##all##auralSpeech synthesizerbrailleBraille devicehandheldHandheld deviceprojectionProjector printPrint preview and print page#screenComputer monitor screenttyMonowidth equipment such as teletypewriterstvTV set
<!doctype html><html lang="en"><head>
    <meta charset="UTF-8">
    <title>Style Test</title>
    <!-- 显示样式 && 小于500px -->
    <style media="screen and (max-width:500px)">
        p{            
        background-color: blue;            
        color: white;        }
    </style>
    <!-- 显示样式 && 大于500px -->
    <style media="screen and (min-width:500px)">
        p{            background-color: grey;            color: white;        }
    </style>
    <!-- 打印样式 -->
    <style media="print">
        p{            background-color: green;            font-weight: bold;        }
    </style></head><body>
    <p>
        注意我的背影颜色吼!!!    </p></body></html>
Copy after login
All devices (Default)

It should be noted that A detailed introduction to HTML5-creating HTML documents, when using the above media attributes, you need to conduct comprehensive testing and prepare unavailable backup styles.
(2) Specify external resources The link tag also supports the media attribute. Among them, the ref attribute determines how the browser treats the link element.

ValueDescription##authorDocument author Help document for the current documentIcon resourceRelated license for the current documentLoad external style sheet
#help
icon
license
stylesheet
<!DOCTYPE html><html lang="en"><head>
    <meta charset="UTF-8">
    <title>Link Test</title>
    <link rel="shortcut icon" href="favicon.ico" type="image/x-icon" /></head><body></body></html>
Copy after login

注意:如果网站标志文件位于项目根目录下,就无需使用link元素加载,其会自动请求加载该文件。

三、使用脚本元素

与脚本相关的有两个元素:第一个是script,定义脚本并控制其执行过程;第二个是noscript,规定浏览器不支持脚本或禁用脚本情况的处理方法。
在引入外部资源时,如果使用自闭合标签,浏览器会忽略这个元素,不会加载引用的文件。
其加载资源时,可以使用async(script元素默认行为是在加载和执行脚本同时暂停处理页面,该属性可以让资源异步加载)和defer(告知浏览器等页面载入和解析完毕后才能执行脚本)控制。【JavaScript异步编程设计快速响应的网络应用】

<!-- 未启用或不支持脚本 --><noscript>
    <!-- 5s后跳转到http://www.php.cn/ -->
    <meta http-equiv="refresh" content="5; http://www.php.cn/"></noscript>
Copy after login

The above is the detailed content of A detailed introduction to HTML5-creating HTML documents. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template