Does anyone know the reasoning behind the strict doctype not allowing input elements to be direct descendents of a form element. I find it annoying that i have to wrap a submit button which is a block level element inside another block level element say a fieldset or a div. However, I cannot find an answer anywhere as to why this actually is.
The strict doctype validates the written code against the HTML 4.01 spec. However, it doesn't allow any deprecated elements or presentational markups such as <font> elements, or framesets to be used.
The <input> tag specifies an input field where the user can enter data. The <input> element is the most important form element.
The <input> element is used to create form fields that accept user input. Form <input> elements can be presented many different ways, including simple text fields, buttons, checkboxes, drop-down menus, and more, by setting the type attribute of the input element to the appropriate value.
So if you try to put an input directly into a form without a container element, and validate under xhtml 1.0 strict, you get this warning:
document type does not allow element "input" here; missing one of "p", "h1", "h2", "h3", "h4", "h5", "h6", "div", "pre", "address", "fieldset", "ins", "del" start-tag ✉ The mentioned element is not allowed to appear in the context in which you've placed it; the other mentioned elements are the only ones that are both allowed there and can contain the element mentioned. This might mean that you need a containing element, or possibly that you've forgotten to close a previous element.
One possible cause for this message is that you have attempted to put a block-level element (such as "<p>" or "<table>") inside an inline element (such as "<a>", "<span>", or "<font>").
And if you look here at the W3C definition of a form element (http://www.w3.org/TR/html4/interact/forms.html#h-17.3) you can see that that the element's content model is defined as "%block".
<!ELEMENT FORM - - (%block;|SCRIPT)+ -(FORM) -- interactive form -->
If you follow the "%block" link (http://www.w3.org/TR/html4/sgml/dtd.html#block) that leads you to the elements that are defined as those types of elements. And those are:
<!ENTITY % block
"P | %heading; | %list; | %preformatted; | DL | DIV | NOSCRIPT |
BLOCKQUOTE | FORM | HR | TABLE | FIELDSET | ADDRESS">
So, as you can see, the W3C doesn't define an input or a button as a block level element. You can search that page for "input" and find that it's content type of "formctrl":
<!ENTITY % formctrl "INPUT | SELECT | TEXTAREA | LABEL | BUTTON">
And, really, input elements default display as more inline-block than block, considering they don't cause line breaks before/after them. So, there are more than just inline elements and block-level elements.
So, in the end, a form needs it's direct children to be block level elements, and input elements don't qualify. I hope that clears everything up.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With