针对不同场景的列表中的 HTML 列表
大家好,我现在正在考虑如何布局店面。
我非常喜欢使用列表,因为从语义上讲,我向用户呈现一个项目列表。然而,我想显示的每个项目的详细信息在语义上也是一个列表。
这是两种不同的场景:
对于缩进项目符号,我通常会这样做:
<ul>
<li>Bullet 1</li>
<li>Bullet 2</li>
<ul>
<li>Indented Bullet 1</li>
<li>Indented Bullet 1</li>
</ul>
</ul>
但是对于上面提到的产品列表,它会更像这样:
<ul>
<li>
<ul>
<li>Product Name</li>
<li>Product Image</li>
<li>Product Author</li>
<li>Product Price</li>
</ul>
</li>
<li>
<ul>
<li>Product Name</li>
<li>Product Image</li>
<li>Product Author</li>
<li>Product Price</li>
</ul>
</li>
</ul>
所以...我的问题是,哪种方式是在列表中使用列表的正确方法?两种方法都对,还是只有一种方法对?如果是的话,是哪个以及为什么?
Hey everyone, I'm currently deciding how to layout a store front.
I'm very fond of using lists because semantically I am presenting the user with a list of items. However the details of each item I want to show is semantically a list as well.
Here's two different scenarios:
For indented bullets I would usually do something like this:
<ul>
<li>Bullet 1</li>
<li>Bullet 2</li>
<ul>
<li>Indented Bullet 1</li>
<li>Indented Bullet 1</li>
</ul>
</ul>
However for the product list mentioned above, it would be more like this:
<ul>
<li>
<ul>
<li>Product Name</li>
<li>Product Image</li>
<li>Product Author</li>
<li>Product Price</li>
</ul>
</li>
<li>
<ul>
<li>Product Name</li>
<li>Product Image</li>
<li>Product Author</li>
<li>Product Price</li>
</ul>
</li>
</ul>
So... my question is, which way is the right way to use lists within lists? Are both ways right, or is only one of them right? If so which and why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
只有第二种方法有效。只有
li
元素可以是ul
(和ol
)元素的子元素。查看 DTD[docs] :
另一方面,
li
元素可以包含所有 <代码>块[文档]和内联
[docs]元素:(
%flow;
<的定义super>[文档])Only the second way works. Only
li
elements can be children oful
(andol
) elements.Have a look at the DTD[docs]:
li
elements on the other hand can contain allblock
[docs] andinline
[docs] elements:(definition of
%flow;
[docs])只有第二种方法是正确的。
ul
元素中允许的唯一元素是li
元素。这可以在标准中看到,例如在规范 DTD。Only the second way is correct. The only elements allowed in an
ul
element areli
elements. This can be seen in the standard, e.g. in the normative DTD.我总是在
中使用
,如下所示:
something
I always use a
<ul>
inside the<li>
like this:<ul><li>something<ul><li>inside</li><ul></li></ul>
第一个是不正确的——你不能这样做。 UL 只能将 li 作为子代。
你必须使用这个模板:
所以第二个就可以了:)
The first one is incorrect - you can't do . UL can have li as child only.
You must use this template:
So the second one is ok :)
我同意从语法上讲,第二个代码片段是正确的。由于您也对语义感兴趣(这很棒!)我想知道以下内容是否可能不是一个改进:
我不是语义标记方面的专家,但我完全支持其背后的想法,所以我会对其他内容感兴趣' 选项。
I concur that syntactically, the second code snippet is correct. Since you're also interested in semantics (which is great!) I wonder if the following might not be an improvement:
I'm no expert in semantic markup, but I fully support the idea behind it, so I would be interested in others' options.
两个代码集都有效。我刚刚编译了它们以及它们的替代语法。输出是相同的。语法上的区别在于 /li 的放置位置,但这并不重要。我按照第一个例子来写。我很惊讶第二个例子起作用了,但它确实起作用了。我 30 年前学习了 Pascal 语言编程,这可能影响了我看待嵌套语句模式的方式。
在环顾四周看看其他人在做什么时,我刚刚学到了一些新东西——描述列表。
http://www.w3schools.com/html/html_lists.asp
Both of the code sets work. I just compiled both of them along with their alternative syntax. Output was identical. The difference in syntax is where the /li is placed, but it doesn't matter. I write it as in the first example. I was surprised the second example worked, but it did. I learned programming on Pascal language 30 years ago, which may influence the way I view the nested statement pattern.
In looking around to see what others do I just learned something new - a description list.
http://www.w3schools.com/html/html_lists.asp