使用 table 代替 css 是不是错了?漂浮?
我在真正使用 CSS 之前就已经制作了网站,并且几年前我就决定使用 CSS 来设计我的网页。离开大桌子并尝试“清除两个”是很麻烦的。
问题是,这么多年过去了,我有时还是会遇到麻烦。每当我遇到糟糕的 CSS 情况时,我都会想起用“table”创建 cols 的简单方法。
我想得越多,就越不明白为什么我们放弃使用表格。它们非常适合设计页面,并不是每个网站都需要 100% W3C 符合,或者有数百个页面因此不支持设计更改。
所以是的,现在我正在考虑重新使用表格。我应该这样做吗?专业设计师是否真的在不应该使用的地方使用了表格?
我还在谷歌地图 API 中偶然发现了一个奇怪的表格。如果谷歌工程师都走这条捷径,为什么我不呢?
(抱歉我的英语不太流利)。
编辑:
很多回复都说这是我的错。我认为 CSS 相当不错,从 Eric Meyer 的书籍开始,自 2005 年以来一直在研究 CSS。我知道这个技巧 width:100%;overflow:auto;
在大多数情况下都有效(而且那时我们还没有这个技巧),但我想知道使用表格在小型网站(例如博客)上快速完成工作是否会是一件坏事。
I've made websites before it was really used, and I've made the decision years ago to use CSS to design my webpages. It was a lot of trouble to leave the great tables and try "clearing both" instead.
The question is, after all those years I still have trouble sometimes. And everytime I run into a bad CSS situation I recall the easy way to make cols with "table".
And the more I'm thinking about it, and the less I understand why we dropped the use of table. They are great to design pages, and not every websites need to be 100% W3C conform or have hundreds of page that wouldn't support a change of design because of that.
So yeah, now I'm thinking about going back using tables. Should I do it? Do pro designers actually use tables where they shouldn't use them?
I also stumbled into a grotesque table in the google map API. If google ingeneers are taking that shortcut, why not me?
(sorry for my english I'm not fluent).
EDIT:
lot of response says it's my fault. I considered being pretty good in CSS, started with books of Eric Meyer and have been doing CSS since 2005. I know that the trick width:100%;overflow:auto;
works in most case (and also that we didn't have this trick bad then), but I wonder if it would be a bad thing to use tables to quickly do the job on smalls website, like a blog.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
当我开始删除表格并使用 CSS 时,我遇到了同样的问题。有时 CSS 浮动可能会很麻烦,在使用它们进行页面布局时会出现一些棘手的边缘情况,但您将学习如何处理它们,这确实是值得的。您的代码大小将减少 10%,并且更易于使用。
另一个考虑因素是 CSS 浮动可以很好地与移动设备和小屏幕配合使用。表格可能会导致真正的问题,特别是如果您想添加不错的触摸屏改进。
许多“专业”设计师在不应该使用表格的情况下使用表格。到处都是。但“专业”往往不等于“好”。表格只能用于可见的数据表格。
I had the same issues when I started dropping tables and using CSS. Sometimes CSS floats can be a pain, there are a few tricky edge-cases that come up when using them for page layout, but you'll learn how to deal with them and it really is worth it. Your code will be 10% of the size and much easier to work with.
Another consideration is CSS floats can be made to work nicely with mobile devices and small screens. Tables can cause real issues with this, especially if you want to add nice touchscreen improvements.
Lots of "pro" designers use tables when they shouldn't. All over the place. But "pro" is often not the same as "good". Tables should only be used for visible tables of data.
表仍然具有重要且语义上正确的正确用法。那是为了表格数据的显示。这在以数据库为中心或使用 ajax 处理大量 xml 的环境中特别有用。对于一般布局,它们不合适,因为这会导致页面加载缓慢,因为浏览器必须等待所有内容才能开始渲染。 CSS 应该不难。如果您遇到问题,您应该看看它在您喜欢的设计的网站上是如何使用的。
CSS 的一大优点是,您可以为网站开发主样式表,然后在各个页面需要细微变化的地方,您可以对特定元素应用覆盖或修改,而无需更改主样式表。
Tables still have an important and semantically correct correct usage. That is for the display of tabular data. That is especially useful in envirnments that are DB-centric or that are process a lot of xml with ajax. For general layout they are not appropriate because the cause slow page loading because the browser has to wait for all contents before it can start rendering. CSS should not be difficult. If you are having trouble you should look at how it is being used on sites where you like the design.
The big advantage of CSS is that you can develop a master stylesheet for a site, and then where individual pages need slight variations you can apply overrides or modifications to specific elements without having to change the master sheet.
避免表格布局带来了很多好处,但归根结底,浏览器仍然过于宽容(目前),你可以摆脱它。如果您对返回它们持谨慎态度,请阅读 display:table 和 css3。它实际上是基于表格的布局,减去表格。
avoiding table layouts offers up a plethora of benefits but @ the end of the day, browsers are still entirely too forgiving (currently) and you can get away with it. if you are wary of going back to them, read up on display:table and css3. it's practically table based layouts, minus the table.
避免使用表格的原因之一是,在加载整个表格的 HTML 之前,表格内的内容不会显示。对于 CSS 方法,情况并非如此。
如果你确实在CSS方法上遇到很多麻烦,那么你一定是做错了。考虑阅读其他人的代码,看看如何做得更好。
One reason tables are avoided is that the content inside of them does not display until the HTML for the entire table has loaded. With the CSS method, this is not true.
If you really have a lot of trouble with the CSS method, you must be doing it wrong. Consider reading over other people's code to see how to do it better.
6 年后(现在是 2017 年),CSS 现在有了 网格 和 flexbox 这应该是构建布局的最简单方法,无需使用丑陋的黑客和表格。
6 years later (we're now in 2017) and CSS now has grids and flexbox which should be the easiest way to build a layout without using ugly hacks and without using tables.