html - 是否可以在表单中使用 <caption> 标签?

标签 html forms

我可以使用 <caption> 吗?表格内的标签?如果不是,为什么不呢?

例子:

<form>
<caption>description</caption>
<label>name:</label>
<input />
</form>

最佳答案

您真的尝试过吗?

答案:不。(好吧,你可以,但它会违反标准)。

<caption> 元素用于为表格添加标题,而不是表单

备选方案:

如果您真的想为表单添加标题,只需添加一个可以使用 CSS 设置样式的有效元素,如下所示:

<form>
    <div class="caption">This is my form caption</div>
    <input .../>
</form>

另一种方法,可能在语义上更正确,是使用 <fieldset> 对表单进行分组:

<fieldset>
    <legend>This is my form caption</legend>
    <form>
        <input .../>
    </form>
</fieldset>

关于html - 是否可以在表单中使用 <caption> 标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4990300/

相关文章:

php - 在 html 表单中使用 javascript 函数在 php 中回显

html - 如何更改 ng-required 中星号符号的颜色

javascript - 全局变量/数组问题

html - 为什么下拉菜单的宽度与我折叠导航栏的链接不相似

html - 使用 Flexbox 的等高卡片

javascript - 滚动条是否在不使用 Javascript 的情况下滚动到底部?

javascript - jQuery 表单验证——正确提交而不是清除错误

php - 使用 HTML 表单将数据插入 MySQL 表

javascript - 具有相同提交/点击功能的 AJAX 多个表单

javascript - PHP:表单防止多个选项卡。