I am asking this question to test the validity of my HTML. I can very well try this out (and I have, and it's possible), but I'm simply curious whether or not this is allowed in HTML. If not, how can one simulate a div or span element inside a form? Using blockquote?
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- Is there a way to play audio on a mobile browser w
- HTML form is not sending $_POST values
- implementing html5 drag and drop photos with knock
Yes.
Did you even try this yourself?
Yes it's valid and you can use any number of divs, spans or blockquotes inside a form. You can always use W3C Markup Validation Service to check your html.
Eg:
Yes, you can. And it is also "officially allowed" by the XHTML standard, if you look into the XHTML XSD, you will find
"block" encompasses
div
and "misc" containsspan
. The "documentation" part points out one particular thing you are not allowed to do: nest aform
within another one.I must correct emboss' answer.
In the XHTML 1.0 Strict DTD that he quotes, the group
misc
does not refer to inline elements. Instead, it refers to the following 4 elements:noscript
,ins
,del
andscript
.So to answer the question, XHTML 1.0 Strict does not allow
span
elements insideform
elements. You'll need to wrap them inside block elements such asp
,dip
orfieldset
.This is not the case with XHTML 1.0 Transitional, though. Indeed, the DTD indicates that inline elements are allowed inside
form
elements:For reference: XHTML 1.0 - DTDs
form
is a block-level element in HTML. Typically, block-level elements allow both block-level and inline children. Bothdiv
andspan
are valid children ofform
.There are a ton of resources online to learn more about this topic, for example:
http://www.w3.org/TR/html4/struct/global.html#h-7.5.3
It may also benefit you to read about the box model, as this is one of the most fundamental concepts of web design/development.
http://www.w3.org/TR/CSS2/box.html