W3C 验证:标签内的有序列表元素
鉴于 和
是内联元素,而
是块元素,那么什么是在不使用脚本的情况下将
嵌套在 span/label 中的正确方法?input { vertical-align: top; }
label { display: block; }
label + label { margin-top: 1em; }
ol { padding:0; margin:0; }
<label for="foo">
<input id="foo" type="checkbox" />
<span style="padding-left: 1em; display:inline-block;">
<ol>
<li>Boat</li>
<li>Jet</li>
<li>Chopper</li>
</ol>
</span>
</label>
<label for="bar">
<input id="bar" type="checkbox" />
<span style="padding-left: 1em; display:inline-block;">
<ol>
<li>Car</li>
<li>Auto</li>
</ol>
</span>
</label>
目标是拥有一个自动排序的列表,它不依赖于 JavaScript,也被认为是 W3C XHTML 有效的。
Given the fact that <label>
and <span>
are inline elements and <ol>
is a block element, what is the proper way to nest an <ol>
inside a span/label w/o using a script?
input { vertical-align: top; }
label { display: block; }
label + label { margin-top: 1em; }
ol { padding:0; margin:0; }
<label for="foo">
<input id="foo" type="checkbox" />
<span style="padding-left: 1em; display:inline-block;">
<ol>
<li>Boat</li>
<li>Jet</li>
<li>Chopper</li>
</ol>
</span>
</label>
<label for="bar">
<input id="bar" type="checkbox" />
<span style="padding-left: 1em; display:inline-block;">
<ol>
<li>Car</li>
<li>Auto</li>
</ol>
</span>
</label>
The goal is to have an automated ordered list, which is not dependent on JavaScript, which is also considered W3C XHTML valid.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用图像映射(
map
)来包含您的列表,但这可能会滥用map
标签。我所说的类似于以下内容:
编辑:W3C 声明
map
属性是块级别的:You could use an imagemap (
map
) to contain your list, but that may be abusing themap
tag.What I'm saying is something like the following:
EDIT: W3C states that the
map
attribute is block level:由于没有人回答,我将尝试一下:
使用 span 手动创建列表
在您看到
ol{...}
或li{...}
在 CSS 中,您必须插入类;ol,.ol{...}
和li,.li{...}
。此外,.ol
可能需要有display:block;
换行符可能会被替换为清晰的,但这都是我的想法,w /o 测试。
Since no one is answering I'll take a stab:
Manually create the list, using spans
Every place you see an
ol{...}
orli{...}
in the CSS, you'll have to insert the class;ol,.ol{...}
andli,.li{...}
. Additionally,.ol
would probably need to havedisplay:block;
The line breaks could probably be replaced by a clear, but this is all off the top of my head, w/o testing.