是的,如果使用得当,一个包含单个项目的列表在语义上是正确的,即使它确实感觉有点奇怪(如果只有一个项目,它就不是一个真正的列表,因为根据定义,一个列表是,嗯, list 项目s,否则它只是一个项目)。
在您提供的示例中,这些项目是占位符并且没有任何意义,因此很难判断它是否适用。它是否正确取决于为什么你把它放在一个子项中。如果它确实是一个列表项,那么拥有一个单项子列表是完全合理的,特别是如果有其他包含多个项的子列表。那样的话,意思就很清楚了。例如,以下是可以的:
<h1>Auto Insurance Customers</h1>
<ul>
<li>
<strong>#1234</strong>
<ul>
<li>2003 Ford Focus</li>
<li>1998 Ford Escort</li>
<ul>
</li>
<li>
<strong>#2468</strong>
<ul>
<li>1999 Lamborghini Diablo VT Roadster</li>
</ul>
</li>
…
</ul>
这个例子没有错,因为一个客户拥有一辆车而其他人可能拥有更多是完全合理的。
另一方面,如果您制作单项子列表的原因只是为了创建一个缩进来偏移和突出列表项的一部分,那么这是不正确的。
例如,假设您有一个文本段落列表。在其中一个段落中,您有一段需要注意的段落,并且您想缩进和偏移它。虽然将它放在列表中会起作用,但这是不正确的,因为您将样式与结构混合在一起。
完成此操作的正确方法是将部分包装在另一个标记中(如<blockquote>、样式<div> 等)并将其保留在该列表项的常规流程中。在以下示例中,需要突出显示列表项之一的一部分。将其放入(单项)列表中是错误的做法:
<h1>Blog posts or something…</h1>
<ul>
<li>
<strong>Foo</strong>
<p>Some long paragraph about Foos, what they do, how they work, etc.</p>
<p>More information about Foos and where they originated.</p>
<p>Instructions on care and feeding of Foos.</p>
</li>
<li>
<strong>Bar</strong>
<p>Detailed description of local watering holes for lawyers.</p>
<p>Anecdotes about experiences of drinking & lawyering.</p>
<!-- This section is to be highlighted and offset to draw attention to it from the rest of this list item. -->
<ul>
<li>
<p>Highlighted account of the subsequent problems and what happened that one strange night.</p>
</li>
</ul>
<p>Summary of what to not do when out drinking with lawyers.</p>
</li>
<li>
<strong>Baaz Luhrmann</strong>
<p>A bunch of stuff about a brass-skinned movie director who made a widely-panned film adaptation of a Shakespeare play who turns to stone and traps your sword when he dies.
</li>
</ul>
相反,您应该为此使用正确的标签。它不仅在语义和结构上正确,而且更清晰,甚至缩小了页面的大小:
<style…>
p.highlight {
margin : 20px 50px;
width : 150px;
}
</style>
…
<li>
<strong>Bar</strong>
<p>Detailed description of local watering holes for lawyers.</p>
<p>Anecdotes about experiences of drinking and lawyering.</p>
<!-- This section is to be highlighted and offset to draw attention to it from the rest of this list item. -->
<p class="highlight">
Highlighted account of the subsequent problems and what happened that one strange night.
</p>
<p>Summary of what to not do when out drinking with lawyers.</p>
</li>