Writing XHTML demands a clean HTML syntax. Writing XHTML demands a clean HTML syntax -------------------------- -------------------------------------------------- -- Some More XHTML Syntax Rules: More XHTML Syntax Rules: Attribute names must be in lower case be quoted Use double quotes for attribute values Attribute minimization is forbidden Attribute abbreviation is not allowed The id attribute replaces the name attribute Replace the name attribute with the id attribute The XHTML DTD defines mandatory elements The XHTML DTD defines mandatory elements---------------- -------------------------------------------------- -------------Attribute Names Must Be In Lower Case Attribute names must be in lower case This is wrong: This is wrong:
This is correct: This is correct:
-------------------------- -------------------------------------------------- ---- Attribute Values Must Be Quoted Attribute values must be quoted in double quotes
This is wrong: This is wrong:
This is correct: That's correct:
---------------------------------------- ----------------------------------------------- Attribute Minimization Is Forbidden Attribute abbreviations are not allowed
This is wrong: This is wrong:
This is correct: The correct one is this:
HTML XHTML compact compact="compact" checked checked="checked" declare declare="declare" readonly readonly="readonly" disabled disabled="disabled" selected selected="selected" defer defer ="defer" ismap ismap="ismap" nohref nohref="nohref" noshade noshade="noshade" nowrap nowrap="nowrap" multiple multiple="multiple" noresize noresize="noresize"
--------------------------------------------- -------------------------------------------------- The id Attribute Replaces The name Attribute id attribute Replaces name attribute HTML 4.01 defines a name attribute for the elements a, applet, frame, iframe, img, and map. In XHTML the name attribute is deprecated. Use id instead. For a, applet, frame, iframe, img and map, HTML 4.01 defines a name attribute, which is deprecated in XHTML and uses id instead. This is wrong: This is wrong:
This is correct: This is correct:
Note: To interoperate with older browsers for a while, you should use both name and id, with identical attribute values, like this:Note: For older browsers, you should use both name and id attributes, and make their values the same, like this :
IMPORTANT Compatibility Note:Compatibility Note: To make your XHTML compatible with today''s browsers, you should add an extra space before the "/" symbol. To make your XHTML compatible with current browsers you should add spaces -------------------------- before the / tag -------------------------------------------------- --- The Lang Attribute Lang Attribute The lang attribute applies to almost every XHTML element. element. It specifies the language of the content in the element If you use the lang attribute in an element, you must add the xml:lang attribute, like this: If you use the lang attribute in an element, you must add On the xml:lang attribute, like this:
Heia Norge!
-------------------------------------------------- ---------------------------------- Mandatory XHTML Elements Mandatory XHTML Elements All XHTML documents must have a DOCTYPE declaration. The html, head and body elements must be present, and the title must be present inside the head element. All XHTML documents must have a DOCTYPE declaration. The html, head and body elements must appear, and the title must be in the head element This is a minimum XHTML document template: This is a minimum XHTML document template oes here>
Title goes here
Body text goes here Note: The DOCTYPE declaration is not a part of the XHTML document itself. It is not an XHTML element, and it should not have a closing tag. Note: The DOCTYPE declaration is not part of the XHTML document itself. It's also not an XHTML element and it shouldn't have a closing tag. Note: The xmlns attribute inside the tag is required in XHTML. However, the validator on w3.org does not complain when this attribute is missing in an XHTML document. This is because "xmlns=http:// www.w3.org/1999/xhtml" is a fixed value and will be added to the tag even if you do not include it. Note: XHTML documents require that the xmlns attribute appears in the html tag. However, w3.org's validator will not report an error because this attribute does not appear in your XHTML document. This is because "xmlns=http://www.w3.org/1999/xhtml" is a fixed value, even if it is not included in your document, it will be added automatically. You will learn more about the XHTML document type definition in the next chapter
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