【发布时间】:2012-04-06 00:07:27
【问题描述】:
我得到了为什么 <p> 元素不能包含 <ul> 元素的技术解释。不幸的是,当这是内容的结构时,这对我没有帮助。
在meta中,我都不懂
- 语义解释,也不
- 推荐的结构
对于我实际上想要显示带有正常内容的“内联”项目列表的情况。
This page 建议将列表与段落分开:
<p>For instance, this fantastic sentence has bullets relating to</p>
<ul>
<li>wizards,
<li>faster-than-light travel, and
<li>telepathy,
</ul>
<p>and is further discussed below.</p>
或为段落使用替代标签:
<div>For instance, this fantastic sentence has bullets relating to
<ul>
<li>wizards,
<li>faster-than-light travel, and
<li>telepathy,
</ul>
and is further discussed below.</div>
但我觉得这两个都是可怕的骇客,是对 HTML5 所谓的语义内容的嘲弄。
在第一种情况下,<p> 标签在语义上有何意义?更不用说如果我想消除列表周围的间距(然后如果我有其他列表确实是单独的内容块 - 哦!)正确设置样式的实际困难!
在第二种情况下,如果我需要 <div> 表示“这是一段内容”,我不妨完全放弃 <p>,而不必根据内容来回切换出现在段落中。
ISTM 认为最具语义意义的版本可能是这样的:
<p>For instance, this fantastic sentence has bullets relating to
<span class="li">wizards,</span>
<span class="li">faster-than-light travel, and</span>
<span class="li">telepathy,</span>
and is further discussed below.</p>
将 span 样式设置为块或列表项(谁知道还有哪些其他调整)以获得正确的渲染。实际上,这听起来非常令人恼火。
对于渲染这种内容有什么好的推荐吗?
编辑
看起来,这实际上并不难设计。我不确定是否有办法获取所有浏览器默认值,但我可以复制默认列表样式(至少在 OS X Chrome 上):
span.li {
display: list-item;
list-style-type: disc;
margin-left: 40px;
}
【问题讨论】:
-
在此处跟进我自己的帖子,由于a longstanding bug,Firefox 中编号列表的样式化跨度技术失败。
标签: html html-lists