我一直听说div标签应该用于布局目的而不是table标签.那么这也适用于表单布局吗?我知道表单布局仍然是一个布局,但似乎创建表单布局与divs需要更多html和css.那么考虑到这一点,表单布局应该使用div标签吗?
通常我使用无序列表标签来设置表单,例如
<fieldset>
<ul>
<li>
<label for="txtName">Name</label>
<input type="text" id="txtName" />
</li>
</ul>
</fieldset>
Run Code Online (Sandbox Code Playgroud)
但是,我经常会看到使用标记的<p>标记,如下所示:
<fieldset>
<p>
<label for="txtName">Name</label>
<input type="text" id="txtName" />
</p>
</fieldset>
Run Code Online (Sandbox Code Playgroud)
哪个在语义上更正确?除了<p>风格更简洁之外,不同的方法是否有任何利弊?
编辑:在这里清楚地打开一罐蠕虫 - 更多选择,哇!:) W3C在这里有推荐吗?
有趣的W3C建议似乎是最不优雅的解决方案:
<p>
<input type="radio" name="flavor" id="choc" value="chocolate" />
<label for="choc">Chocolate</label><br/>
<input type="radio" name="flavor" id="cream" value="cream"/>
<label for="cream">Cream Filled</label><br/>
<input type="radio" name="flavor" id="honey" value="honey"/>
<label for="honey">Honey Glazed</label><br/>
<input type="submit" value="Purchase Donuts"/>
</p>
Run Code Online (Sandbox Code Playgroud)
遗憾的是,关于标记表单元素的最佳约定没有更强的指导.