[thelist] CSS Form layout w/out span|div

RUST Randal RRust at COVANSYS.com
Fri Feb 21 07:14:04 CST 2003


Lachlan Cannon said:

> Suddenly I have to wonder how many people actually know how
> the specs work.

> Morgan, your way of making labels is correct. So is Ben's.
> You can either use the for attribute on the label tag OR wrap
> the appropriate field in the label tag. Either is supposed to work.

Lachlan's comments got me curious, as I haven't ever actually *seen* any
examples of <input> inside of a <label> [1], so I went looking at the
XHTML Transitional DTD for verification.

<!--
  Each label must not contain more than ONE field
  Label elements shouldn't be nested.
-->
<!ELEMENT label %Inline;>
<!ATTLIST label
  %attrs;
  for         IDREF          #IMPLIED
  accesskey   %Character;    #IMPLIED
  onfocus     %Script;       #IMPLIED
  onblur      %Script;       #IMPLIED
  >

So there you have it. A label can contain one inline element. So what I
said yesterday about <label> needing to come before the <input> was not
correct.

[1] And if I had looked here more closely, I would have seen it.
http://www.w3.org/TR/html401/interact/forms.html#h-17.9 The key is that
Ben's method is *implicit.* In this case, you cannot use a table for
layout, and you do not need the "for" and "id" attributes. But the more
common method is *explicit.* The other major problem with this implicit
method is browser support. Until recently, Netscape didn't support the
<label> element, but it does now, AFAIK. This is very interesting
though, and something I will be giving some more thought to:)

----------
Randal Rust
Covansys Corp.
Columbus, OH



More information about the thelist mailing list