我什么时候应该使用表格、div 或 uls?
Possible Duplicate:
Why not use tables for layout in HTML?
When should I use <table>
, <div>
or <ul>
?
What are the main advantages and disadvantages of each one?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
始终尝试根据其语义字符使用每个标签
表格用于表格数据,而不是布局对齐
是无序列表,这很好使用
标签作为
链接,因为没有 CSS 后备
div 没有语义含义,主要用于对齐,但是 HTML5 附带了许多新标签,例如
、
always try to use each tag according to its semantic character
<table>
tables are for tabular data, not for layout alignment<ul>
is unordered list, it is nice to use<ul>
tag for<a>
links, because of no CSS fallback<div>
div has no semantic meaning, mostly used for alignment, however HTML5 comes with a lot of new tags as<header>
,<footer>
,<article>
,<section>
,<aside>
which should be used insted of div tag从语义上讲,您应该对表格数据使用表格,对无序列表使用无序列表,对没有可用语义定义元素的情况使用分区。不过,还有解释的空间。例如,一些开发人员将导航菜单视为无序列表,因此使用无序列表标签(可能风格很重)。
在 HTML4 之前,普遍缺乏语义元素,因此开发人员觉得有必要经常使用划分。然而,HTML5 引入了一系列块级语义元素,这些元素定义文档结构并且比分区具有更多含义,尽管它们的行为应该相同。这些新标签包括文章、部分、页脚、导航、旁白和页眉。
Semantically, you should use tables for tabular data, unordered lists for unordered lists, and divisions where there is no semantically-defined element available. However, there is room for interpretation. For example, some developers think of navigation menus as unordered lists, and thus use unordered list tags (probably heavily styled).
Up to and including HTML4, there was a general lack of semantic elements, so developers felt the need to fall back to using divisions very often. However, HTML5 introduces a range of block-level, semantic elements that define document structure and have more meaning than divisions, though they should behave the same. These new tags include article, section, footer, nav, aside and header.
这是一个有争议的问题,我在这里仅提出我个人的观点:
我认为只有当您必须显示表格数据时才应该使用表格。
请勿使用表格进行定位/布局;为此使用 div 和 css。
有关更多详细信息,请参阅此问题。
this is a matter of some debate, and I present only my personal view here:
I think you should use tables only when you have to display tabular data.
do NOT use tables for positioning / layout purposes; use divs and css for that.
see this question for more details.