表而不是DIV [英] Tables instead of DIVs

查看:145
本文介绍了表而不是DIV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

为什么不在HTML中使用表格布局?

在什么条件下,您应该在HTML编码中选择表格而不是DIV?

Under what conditions should you choose tables instead of DIVs in HTML coding?

推荐答案

事情只是勉强错过了标记。它不是表或div。它是关于使用语义html。

The whole "Tables vs Divs" thing just barely misses the mark. It's not "table" or "div". It's about using semantic html.

即使div标签只在一个很好的布局页中的一小部分。不要过度使用它。你不应该需要那么多,如果你把你的html在一起正确。列表,字段集,图例,标签,段落等内容可以替代div或span经常用来完成的大部分内容。 Div应该主要用于指示逻辑** div ** ision,并且只在绝对必要时适用于额外布局。表同样如此;

Even the div tag plays only a small part in a well laid out page. Don't overuse it. You shouldn't need that many if you put your html together correctly. Things like lists, field sets, legends, labels, paragraphs, etc can replace much of what a div or span is often used to accomplish. Div should be used primarily when it makes sense to indicate a logical **div**ision, and only appropriated for extra layout when absolutely necessary. The same is true for table; use it when you have tabular data, but not otherwise.

然后你有一个更语义的页面,你不需要相当多的类定义在你的CSS;您可以直接指定广告代码。可能最重要的是,你有一个页面,将获得比谷歌(轶事)比同等的表或肮脏的页面更好。

Then you have a more semantic page and you don't need quite as many classes defined in your CSS; you can target the tags directly instead. Possibly most importantly, you have a page that will score much better with Google (anecdotally) than the equivalent table or div-heavy page. Most of all it will help you better connect with a portion of your audience.

所以,如果我们回头看看表vs div,这是我的意见我们实际上已经达到了div被过度使用,表未被充分利用的地步。为什么?因为当你真正想到它,有很多事情在那里,属于表格数据,往往被忽视的类别。例如,在这个非常网页上的答案和评论。它们由多个记录组成,每个记录具有相同的字段集。他们甚至存储在一个sql服务器表,大声哭泣。这是表格数据的确切定义。这意味着html表标签绝对是一个很好的语义选择来布局像这里的帖子在StackOverflow。同样的原则也适用于许多其他事情。使用表标记来设置三列布局可能不是一个好主意,但它可以很好地用于网格和列表...除非,当然,当你可以实际使用ol或ul列表)标签。

So if we go back and look at it in terms of table vs div, it's my opinion that we've actually come to the point where div is over-used and table is under-used. Why? Because when you really think about it, there are a lot of things out there that fall into the category of "tabular data" that tend to be overlooked. Answers and comments on this very web page, for example. They consist of multiple records, each with the same set of fields. They're even stored in a sql server table, for crying out loud. This is the exact definition of tabular data. This means an html table tag would absolutely be a good semantic choice to layout something like the posts here on StackOverflow. The same principle applies to many other things as well. It may not be a good idea to use a table tag to set up a three column layout, but it's certainly just fine to use it for grids and lists... except, of course, when you can actually use the ol or ul (list) tags.

这篇关于表而不是DIV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆