Is it possible to use a <caption> tag in a form?
Can I use the 开发者_Python百科<caption>
tag inside a form ? If not, why not?
Example:
<form>
<caption>description</caption>
<label>name:</label>
<input />
</form>
Have you actually tried it first?
Answer: no. (Well, you can, but it would break standards).
The <caption>
element is used to caption a table, not a form.
Alternative solution:
If you really want to caption forms, simply add a valid element that can be styled with CSS to it, like so:
<form>
<div class="caption">This is my form caption</div>
<input .../>
</form>
Another approach, that would probably be more semantically correct, would be to use a <fieldset>
to group your form:
<fieldset>
<legend>This is my form caption</legend>
<form>
<input .../>
</form>
</fieldset>
You are looking for the <legend>
tag, perhaps?
No, the caption
element pertains specifically to tables. One may argue it's a strange case of omission on part of whoever helped make HTML what it is today, but be it as it may, it cannot be used with forms. Furthermore, there are semantical implications of trying to use caption
for a form, since it captions tables and not forms.
The idiomatic way to "caption" or "head" content in HTML, including announcing forms and form content, is to use the heading tags h1
, h2
etc. These are generic with regard to what they help announce and you may therefore well precede or nest these within a form
element.
In your case you would then have:
<form>
<h1>description</h1>
<label>name:</label>
<input />
</form>
or you could also put the heading element directly preceding the form
element:
<h1>description</h1>
<form>
<label>name:</label>
<input />
</form>
I think the former is more semantically applicable, but sometimes certain factors like abilities of CSS, will necessitate use of the latter. Either should be valid, regardless.
精彩评论