Something in HTML Image link syntax doesn't make sense to me
<A HREF="http://www.computerhope.com"> <IMG SRC="http://www.computerhope.com/logo.gif"> </a>
This is a propere syntax of how to link an image.
Two questions:
What does the ">" after the href value closes? Obviously 开发者_JS百科the "< A" is being closed by the "/a" at the very end. It seems like there's an extra closing ">" here, but that is the right syntax.
Why is the
<IMG>
closed by ">
" and not "/>
" or "</IMG
"?
Thanks.
What does the ">" after the href value closes?
That indicates the end of the current tag. (i.e. the end of the anchor start tag)
Obviously the "< A" is being closed by the "/a" at the very end. It seems like there's an extra closing ">" here, but that is the right syntax.
The anchor has a start tag (<a>
+ attributes) and an end tag (</a>
).
Why is the
<IMG>
closed by ">
"
The image element is defined as EMPTY (i.e. it cannot contain anything) so the end tag is (in HTML 4) unnecessary, pointless and thus forbidden.
and not "
/>
" or "</IMG
"?
Because it is not XHTML. XHTML is based on XML rather then SGML and can't have optional or forbidden tags. The end tag must be included explicitly in XHTML (or self-closing syntax must be used (<foo />
) to represent the entire element as a single tag).
What does the ">" after the href value closes?
HTML elements with content always have a start tag <tag>
and an end tag </end>
. In between there is the content. Just like XML. Otherwise there would be no way to tell, what is an attribute and what is the content.
Why is the closed by ">" and not "/>" or "
Not sure to which element you refer, but if it is IMG
: elements without content, don't need an end tag (unlike in XML, where you would write this as self-closing tag <img ... />
).
Have a look at the HTML 4 specification:
Each element type declaration generally describes three parts: a start tag, content, and an end tag.
The element's name appears in the start tag (written
<element-name>
) and the end tag (written</element-name>
); note the slash before the element name in the end tag. For example, the start and end tags of theUL
element type delimit the items in a list:<UL> <LI><P>...list item 1... <LI><P>...list item 2... </UL>
Some HTML element types allow authors to omit end tags (e.g., the
P
andLI
element types). A few element types also allow the start tags to be omitted; for example,HEAD
andBODY
. The HTML DTD indicates for each element type whether the start tag and end tag are required.
The a tag is an anchor tag so it needs something between the opening and closing tag to be the anchor text or in this case image.
Syntax for the anchor tag is
<a href="url/link">....</a>
What ever you put where the ... is, is the anchor for the link being either text or image.
Some tags doen't have an opening and closing tag like the a tag.
<a href=""></a>
Image tags simply close with the /> or > depending on which version of html you are writing.
<img src="" >
精彩评论