通常,我使用无序列表标签为表单设置样式,例如
<fieldset>
<ul>
<li>
<label for="txtName">Name</label>
<input type="text" id="txtName" />
</li>
</ul>
</fieldset>
但是,我经常看到使用<p>
标签的标记,如下所示:
<fieldset>
<p>
<label for="txtName">Name</label>
<input type="text" id="txtName" />
</p>
</fieldset>
以下哪个在语义上更正确?<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>
遗憾的是,没有关于标记表单元素的最佳约定的更强有力的指导。