Introduction to the Web standard learning path: 4. doctype and life-space

Source: Internet
Author: User
Tags color identifier

Disclaimer: this series of e-books and other data collection from <Author: A Jie>.

 

Doctype

Preface

Hello everyone! This seriesArticleThe website is created by Alibaba Cloud. Alibaba Cloud has never created a website that truly complies with web standards. Now, I am referring to foreign materials and recording my experiences and experiences. I hope this will be helpful to you. Okay. Let's get started.

Start to make a site that meets the standards. The first thing is to declare the doctype that meets your needs.

View the original homepage of this siteCode, You can see that the first line is:

<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en ""Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

Open some standards-compliant websites, such as well-known web design software developersMacromedia, Design masterZeldmanThe same Code will be found on the personal website. Other websites that comply with the standards (for exampleK10k.netThe Code is as follows:

<! Doctype HTML public "-// W3C // dtd xhtml 1.0 frameset // en ""Http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">

So what do these codes mean? Are you sure you want to place it?

What isDoctype

doctype statement. doctype Yes document type ( document type ) , used to describe the XHTML or HTML version.

DTD ( for example, in the above example xhtml1-transitional.dtd) document type definition , contains document Rules , the browser defines DTD to explain the logo of your page , .

To create a standard web page, the doctype Declaration is an essential part. Your logo and CSS will not take effect unless your XHTML determines a correct doctype.

XHTML 1.0 provides three types of DTD declarations:

: transition (Transitional ): very loose DTD , it allows you to continue using html4.01 identifier ( but must comply with XHTML ) . The complete code is as follows:

<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en ""Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

·Strict(Strict ):Strict requirementsDTD,You cannot use the identifiers and attributes of any presentation layer.,For example<Br>. The complete code is as follows:

<! Doctype HTML public "-// W3C // dtd xhtml 1.0 strict // en ""Http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

·Framework(Frameset ):Designed and used for frame pagesDTDIf your page contains a framework, you need to use thisDTD. The complete code is as follows:

<! Doctype HTML public "-// W3C // dtd xhtml 1.0 frameset // en ""Http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">

What do we choose?Doctype

The ideal situation is strict. DTD , But for most of us Web Standard designers , Transitional DTD (XHTML 1.0 transitional) Is the current ideal choice ( Including this site , It is also a transitional type. DTD) . Because this DTD also allows us to use the identifier, element, and attribute of the presentation layer, it is easier to pass W3C code verification.

Note: The "presentation layer identifier and attribute" mentioned above refers to the tags purely used to control the presentation, such as the table used for typographical layout and background color identifier. In XHTML, identifiers are used to represent structures rather than representations. Our purpose of transition is to ultimately separate data from representations.

For example, a human model changes clothes. Models are like data. clothes are the form of representation. Models and clothes are separated so that you can change clothes at will. In html4, data and performance are mixed, and it is very difficult to change the form at one time. It's a bit abstract. We need to gradually understand this concept in the application process.

Supplement

The doctype Declaration must be placed at the top of each XHTML document, on top of all codes and identifiers.

Namespace

After the doctype is declared, the following code is:

<HTML xmlns = "http://www.w3.org/1999/xhtml" lang = "gb2312">

Generally, our html4.0 code is just <HTML>. What is "xmlns" here?

" xmlns " Yes XHTML namespace , called " namespace " statement. What is the role of namespace? ? Alibaba Cloud understands :

Because XML allows you to define your own identifiers, the identifiers you define may be the same as those defined by others, but they indicate different meanings. Errors may occur when files are exchanged or shared. To avoid such errors, XML uses namespace declarations, allowing you to identify your identity through a URL. For example:

Both Mr. Wang and Mr. Li have defined a <book> identifier. If Mr. Wang's namespace is"Http://www.xiaowang.com", Xiao Li's namespace is"Http://www.xiaoli.com", The <book> identifier will not be confused when two documents exchange data because it belongs to different namespaces.

The more common explanation is that namespace is to mark the document and tell others who the document belongs. But this "who" is replaced by a URL.

XHTML is the identifier language for the transition from HTML to XML. It must comply with XML document rules, so you also need to define the namespace. Because xhtml1.0 cannot be a user-defined identifier, its namespace is the same, that is"Http://www.w3.org/1999/xhtml". It doesn't matter if you don't quite understand it. At present, we only need to copy the code.

The following lang = "gb2312" specifies that your document is in simplified Chinese.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.