在HTML中,表格不应该用于布局,这似乎是普遍的观点。
Why?
我从来没有(老实说,很少)看到过支持这一点的有力论据。通常的答案是:
It's good to separate content from layoutBut this is a fallacious argument; Cliche Thinking. I guess it's true that using the table element for layout has little to do with tabular data. So what? Does my boss care? Do my users care?Perhaps me or my fellow developers who have to maintain a web page care... Is a table less maintainable? I think using a table is easier than using divs and CSS.By the way... why is using a div or a span good separation of content from layout and a table not? Getting a good layout with only divs often requires a lot of nested divs.
Readability of the codeI think it's the other way around. Most people understand HTML, few understand CSS.
It's better for SEO not to use tablesWhy? Can anybody show some evidence that it is? Or a statement from Google that tables are discouraged from an SEO perspective?
Tables are slower.An extra tbody element has to be inserted. This is peanuts for modern web browsers. Show me some benchmarks where the use of a table significantly slows down a page.
A layout overhaul is easier without tables, see css Zen Garden.Most web sites that need an upgrade need new content (HTML) as well. Scenarios where a new version of a web site only needs a new CSS file are not very likely. Zen Garden is a nice web site, but a bit theoretical. Not to mention its misuse of CSS.
我对使用divs + CSS而不是表的良好参数非常感兴趣。
这并不一定是一场战争。和谐是可能的。
使用一个表的整体布局和div在其中。
<table>
<tr><td colspan="3"><div>Top content</div></td></tr>
<tr>
<td><div>Left navigation</div></td>
<td><div>Main content</div></td>
<td><div>Right navigation</div></td>
</tr>
<tr><td colspan="3"><div>Bottom content</div></td></tr>
</table>
看,没有嵌套表。
我读过很多关于如何用divs实现这一点的文章,但从来没有发现任何事情,每次都没有问题。
一旦你有了整体结构,Divs是很棒的,但坦率地说,流体页眉/页脚和三个流体列是Divs的一大痛苦。Divs不是为流动性而设计的,所以为什么要使用它们呢?
注意,这种方法将在链接文本中提供100%的CSS遵从性
我认为没有人会在意一个网站是如何设计/实现的,当它运行得很好并且运行得很快的时候。
我在HTML标记中同时使用“table”和“div”/“span”标记。
让我给你一些我为什么选择跳水的理由:
for a table you have to write at least 3 tags (table, tr, td, thead, tbody), for a nice design, sometimes you have a lot of nested tables
I like to have components on the page. I don't know how to explain exactly but will try. Suppose you need a logo and this have to be placed, just a small piece of it, over the next page content. Using tables you have to cut 2 images and put this into 2 different TDs. Using DIVs you can have a simple CSS to arange it as you want. Which solution do you like best?
when more then 3 nested tables for doing something I am thinking to redesign it using DIVs
但是我仍然在使用表格:
表格数据
扩展自我的内容
快速解决方案(原型),因为DIVs盒子模型在每个浏览器上是不同的,因为许多生成器使用表格等
The issue of strictly separating presentation and content strikes me as roughly analogous to separating header files from implementation files in C++. It makes sense, but it can also be a pain. Witness Java and C# where classes are defined in a single source file. The authors of the newer languages noticed something that was causing programmers headaches and they got rid of it. That seems to be the gist of this discussion. One side is saying CSS is too difficult, the other side is saying one must become a CSS master.
对于简单的布局问题,为什么不改变表示必须完全独立的规则呢?一个新的标签(或者一些div标签的扩展)可以让我们直接在HTML中控制显示?毕竟,我们不是已经将表示泄露到HTML中了吗?看看h1, h2, h6。我们都知道这些控制表示。
阅读代码(HTML就是代码)的能力非常重要。专家们往往忽略了使编程环境尽可能为大众所接受的重要性。认为只有专业程序员才重要是非常短视的。