Learn Web metrics to choose the right type of document for your Web page

Source: Internet
Author: User
Tags contains object model relative resource valid
Web|web Standard | Web page You do everything you think is right, but the page does not behave correctly in the latest browsers. That's what you wrote. Invalid XHTML and CSS. You use the standard Document Object Model (DOM) of the consortium to manipulate page dynamic elements. And in the browser to show these standards, your site is not valid. This is most likely caused by an incorrect document type (DOCTYPE). This article will provide you with an explanation of how DOCTYPE works, as well as the use of these document types in the real world.

Why use document types (Why a DOCTYPE?)

Based on the HTML and XHTML standards, a DOCTYPE (shorthand for "document type declaration") is used to tell the browser which version of (x) HTML you are using, and must be present at the top of every page. DOCTYPE is an important component of Web pages: Without them, your CSS will no longer be valid.

As with the ALA article mentioned earlier (and other interesting places as well), DOCTYPE also adapts to other browsers, such as Mozilla, Ie5/mac, or IE6,IE7.

A new doctype contains an entire URI (sconf Note: Universal Resource Identifier, Universal Resource Identifier) (a complete URL) that tells browsers to parse the page (render) into a model that is appropriate to the standard. Treat (X) HTML, CSS, and Dom as you would expect.

Using an imperfect or old doctype, or even not using DOCTYPE, will allow the browser to convert it into a "Quirks" model, at which point the browser assumes that you are writing outdated, mangled code after the 90 's.

With this setting, the browser will try to parse your page with the old standard, parsing your CSS into a IE4 standard. and reply to the owner a special dom (ie responded to IE's Dom,mozilla and Netscape 6 responded to what they thought was the model).

No doubt, it's not what you want. But it's what you always get. So this article would like to correct these incorrect or incomplete doctype.

(Note: Opera browsers do not support these rules, it always tries to parse the Web page into a standard adaptation, and on the other hand, opera does not provide too strong support for the DOM of the Consortium.) But they can also run well. Ed: Since the first time this article was published, opera has added the adapted DOM (dom-compliant) to the Opera7.

Where's doctype? (Where HAVE All the Doctypes GONE?)

Although the Web standards of document types in browsers are an important organic component, despite the Web standards created by the leaders of the consortium, you also expect the site to be able to provide some appropriate document types, and you may want to quickly and easily find this information, however, when I write this article, you can not. {ED:W3C Now lists a list of standard doctypes on his web site where you can see this in the World Wide Web guide, such as "my website site is standard." And yours? "}

W3.org is not a List Apart, webreference or Webmonkey. It was not intended to help web designers, developers, and civil society to speed up their understanding and use of the latest technology. It's not his job.

The consortium publishes a series of guidelines, although most web designers are rarely aware of them. #

You can search the doctypes on the w3.org all day long without having to look at those special lists. And when you do download a doctype (usually related to some special advice or work draft), it doesn't work on your site abnormally.

All over the Web site is the doctypes of missing URIs (sconf: That is, not the end of the URI), which points to the Web site of the worldwide network. Once these are transferred from the Web to your own pages, the URLs will become non-existent documents.

For example, the DOCTYPE of many sites are directly replicated on w3.org:

"Dtd/xhtml1-strict.dtd" >
If you see the last part of this doctype ("Dtd/xhtml1-strict.dtd"). You will find that this is a relative link to the Web site. This is on the world's web site, not yours. So this URI has no effect on the browser. (sconf Note: When you visit w3.org, it works because it's a relative link.)

This doctype should actually be changed to:


"Http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" >
Note that the following DOCTYPE contains a complete URI. This shows a valid resource on a network and the browser can find it and parse your document into a standard adaptive (standards–compliant) type.

How to use DOCTYPE (Doctypes that WORK)

So how should doctype be used? I'm glad you asked. The following complete DOCTYPE is what we need:

HTML 4.01 rigorous type, transition type, frame type

"Http://www.w3.org/TR/html4/strict.dtd" >

"Http://www.w3.org/TR/html4/loose.dtd" >

"Http://www.w3.org/TR/html4/frameset.dtd" >
XHTML 1.0 Rigorous type, transition type, frame type

"Http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" >

"Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >


"Http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd" >
XHTML1.1 DTD

"Http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" >

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.