问题
Is it considered valid to do the following:
<li>stuff</li class="randomlengthclassname">
<li>stuff</li class="shortclassname">
<li>stuff</li class="reallyreallylongarseclassname">
or do the attribute have to be in the opening tag?
回答1:
No it isn't. You must use attributes in the opening tag.
Running <a>test</a href="tst.html">
in w3c validator results in this error:
name start character invalid: only S separators and TAGC allowed here
Where S separators and TAGC are:
S is "whitespace" separator
[5] s =
SPACE | (32) space
RE | (13) CR
RS | (10) LF
SEPCHAR (9) HT
-- http://xml.coverpages.org/sgmlsyn/sgmlsyn.htm#C6.2.1
TAGC ">"
-- http://www.w3.org/TR/sgml.l
回答2:
This is not valid, and all attributes must be defined in the opening tag, indeed.
回答3:
The attribute has to be in the opening tag. The code which you have presented probably wouldn't work.
回答4:
Attributes should appear in the element's start tag. Quoting the W3C: On SGML and HTML Attributes:
... Attribute/value pairs appear before the final ">" of an element's start tag. Any number of (legal) attribute value pairs, separated by spaces, may appear in an element's start tag. They may appear in any order.
回答5:
Closing tags may not contain attributes.
But in HTML4 you may omit the closing LI
:
<!ELEMENT LI - O (%flow;)* -- list item -->
<!ATTLIST LI
%attrs; -- %coreattrs, %i18n, %events --
>
Start tag: required, End tag: optional
In XHTML, you may not.
来源:https://stackoverflow.com/questions/3599936/attributes-in-elements-closing-tag