tags:

views:

1011

answers:

18

I am developing a "modern" website, and I'm having a lot of trouble getting the CSS to make everything line up properly. I feel like they layout would be a lot easier if I just used a table, but I've been avoiding <table> tags, because I've been told that they are "old-fashioned" and not the right way to do things.

Is it okay to use tables? How do I decide when a table is appropriate, and when I should use CSS instead? Do I just do whatever is easier?

+20  A: 

Tables should be used to represent tabular data. CSS should be used for presentation and layout.

This question has also been exhaustively answered here:

http://stackoverflow.com/questions/83073/div-vs-table/84986#84986

Wayne Koorts
Another one CSS freak. Go out and practice a little bit first before giving stupid advices.
User
Irony. Perhaps you'd like to raise a question so SO can solve the problems you've been having with CSS, Mastermind?
annakata
+1  A: 

its ok to use tables when you are showing data in a grid / tabular format. however, for general structure of the site, its highly recommended that you use css driven div, ul, li elements to give you more lucid website.

If you anyways decide to work with tables, you must consider the following cons :

  • they are not SEO friendly
  • they are quite rigid in terms of their structure and at times difficult to maintain as well

you may be spending little extra time on div based website, but its worth every minute spent.

Vikram
+1  A: 

Table is always the right choice when you have the need to present data in a grid.

Greco
+6  A: 

In the 'modern' approach of tables it is not about using table tags or div tags, but about using the right tag for the right purpose.

The table tag is used for tabular data. There is nothing wrong with using it for that!

For using CSS, there are a lot of tutorials and guides (good and bad) around. Indicators of a bad tutorial are: lot of use of blocks (divs) that only make sense for the layout and not for the content. Good signs are the ones that advise to use the right tags for the right content and teach you how to make up that tags.

Peter Smit
Good answer that shows the stupidity of all these "tables vs divs" questions!
roryf
+19  A: 
womp
Where did I say anything about inline styling? And tables are wholly appropriate for layout when needed, as 8 other responses on here will attest to. There's nothing "legacy" about tables, except for the fact that they were abused for years.
womp
Chill annakata! No one will die if a table is used for layout. Well, no one important anyway.
marcus.greasly
Look I really think you're overreacting - if it makes you feel better I'll delete my comments, but just to *further* clarify: your language is ambiguous and the subject is not. Now if I rescind my downvote will you go and take your retaliatory one off? It's just a downvote, I think we can all move on with our lives can't we?
annakata
Sorry. I was ultra-grouchy last night, I have two presentations to give today and someone on my team broke the build when I really needed it, so I was up until 2 AM.
womp
That is an awesome graphic....and it is so true.
Michael Kniskern
+2  A: 

Tables are only appropriate for tabular data. Imagine you have to add some spreadsheet like data, where you have clear row/column headers, and some data inside those rows. A product comparison, for example, is also a valid table item.

Gidon
+4  A: 

I believe that tables are OK for display of rectilinear data of arbitrary rows and/or columns. That's about it. Tables should not be used for layout purposes anymore.

Glenn
Yours looks like the first post which actually makes an attempt to explain what 'tabular data' is. Ie, it is data in rows and columns. +1!
thomasrutter
+1  A: 

Quoting Sitepoints's book HTML Utopia: Designing Without Tables using CSS If you have tabular data and the appearance of that data is less important than its appropriate display in connection with other portions of the same data set, then a table is in order. If you have information that would best be displayed in a spreadsheet such as Excel, you have tabular data.

Andy Dent
+1  A: 

I would say no for using tables to construct your layout. Tables make sense only for actual tabular data you need to represent. If you spend enough time figuring the CSS out you will find its easier then using tables for a layout. Just remember: Tables for displaying data. CSS for page layouts.

teh_noob
A: 

Tables are just that: Tables.

They are frowned upon because they should not be used for layout, as has been the fashionable thing to do before browsers could position stuff properly.

If what you want to markup is, in fact, a table, then use a table. Other than that, try to stay away.

One small thing: Aligning two parts of text to the exact same line that won't move apart (think, username and post date). There using a table is IMHO an option.

kungfoo
You don't need to use tables for that: if you know how to float elements correctly, you can make perfectly aligned columns with just CSS.
htw
+9  A: 

essentially, if you have tabular data, then use a table. There's really no need now to use tables for layout - sure, they were often considered 'easier' but semantically the page is horrid, they were often considered inaccessible.

See some discussion: css-discuss

and a particularly comical URL: http://www.shouldiusetablesforlayout.com/

Terry_Brown
+1 for the website :)
furtelwart
be sure to look at the source of that second link once you've marveled at the beauty of the page by the way :)
Terry_Brown
awesome website :)
Mafti
A: 

I'd recommend you read up on grid-based CSS layouts. You don't necessarily have to use one of the existing frameworks, but if you understand their techniques, you should be able to get things aligned very well.

Chuck
A: 

In general, HTML markup should describe the structure and content of a web page—it should not be used to control presentational aspects such as layout and styling (that's what CSS is for). A <table> tag, like most have already said, should represent tabular data—something that would appear as a table of information.

The reason why people rag on tables so much is that in the old days, there was no such thing as CSS—all page layout was done directly in HTML. Tags were not thought of as describing content—all anyone really cared about was how a tag would make things look in a web browser. As a result of this, people figured that, since they could organize things into rows and columns, tables must be good for laying out elements of a web page. This became a really popular technique—in fact, I'd wager that using tables was considered the preferred method of laying out web pages for quite some time.

So when people tell you that tables are "old-fashioned," they are specifically referring to this abuse of the <table> tag that was so popular back in the old days. Like I said, there's nothing wrong with HTML tables themselves, but using them for web page layout just doesn't make sense nowadays.

(Plus, from a purely pragmatic standpoint, layouts done with HTML tables are very inflexible and hard to maintain.)

htw
+2  A: 

If I could, I'd give http://giveupandusetables.com/ an "Insightful +1".

No, seriously, I would.

Henrik Paul
A: 

First get it working. Then get it perfect.

Get the layout done in some way before making it perfect or better.

How many people per day will go to the page you are working on? A million? or 20 ?

How much time are you going to spend on CSS issues instead of other issues? Does your boss want you to spend this much time on the issue? Does he/she know what you are doing?

Pat
A: 

Absolutely. I don't know where CSS zealots invented the idea that tables are not naturally used for "layout". Tables have been used for laying things out since their invention, whether those things be numbers, words, or pretty pictures. That's what they do. Moreover, table is part of all versions of (X)HTML so there are no deprecation concerns.

Matthew Flaschen
I think you're confusing the <table> with grids.
roryf
I think you wildly misunderstand the difference between intent and necessity.
annakata
No, I'm not confused. <table> is a very effective way to implement a table, which is the most common form of grid.
Matthew Flaschen
And nothing whatsoever to do with laying out anything which isn't a table.
annakata
A: 

The whole "anti-Table" movement is a reaction to a time when deeply nested tables were the only method to layout pages, leading to HTML that was very hard to understand.

Tables are a valid method for tabular (data) layout, and if a table is the easiest way to implement a layout, then by any means use a table.

mfx
Define "easiest". For me using tables is harder because I don't know how to do layouts with them anymore, if they don't contain data I'm lost. Now give me some nice lists, paragraphs etc. and I fell right at home, same as a nice <thead>, <tbody> structure.
roryf
"Easiest" depends upon many factors, amongst them your css knowledge and what browsers you program for. I have often implemented a nice-looking layout in css, only to fall back to a table because i couldn't persuade IE6 to display it correclty ;-)
mfx
A: 

Absolutely.

All that HTML offers was originally intended for you to define the markup of your page. In my book, absolute and relative positions of elements on a page belong to markup. So both divs and tables are very much suited for this task. Pick up what works best for your particular need.

CSS adds many styling possibilities and also layout tricks but it complements HTML options not replaces them.

There is actually a very fine line between seeing something as a markup or styling issue. CSS proponents would say that with CSS you can relocate and reshuffle completely all big and little pieces of a page. I cannot however imagine putting header below, footer above and making things appear in reverse order.

Take an example. You design a notebook. You know where to place major components, mainboard, cooling system, keyboard, display and ports. You may certainly wish to rearrange a little bit port connectors, on whic side and in which sequence they appear, but you don't really expect to put display where the keyboard is, put keyboard on the lid, make fans blow to your face and have all connectors on the botom to be reached through holes on your desk.

Using tables can make it slightly difficult to rearrange elements on a page. This might be true. However, in most cases you know in advance how approximately your page should look like and you would not want to change everything drastically. if you can't say it before your begin your work you probably have no clear idea what you are doing and what for.

Moreover, only tables possess elastic properties, which allows the to stretch to the width/height of their content. Nothing else of HTML/CSS can be used to do that.

CSS design on one side allows you to create quite adjustable designs. On the other hand, it locks you out from designing a page adjustable to its content. Both wins and losses.

Table is also the only tool to make very complex and precise interfaces. For example, the page SO is very simple. It probably can be done with pure CSS. In the meantime, have you seen any enterprise-class software like CRMs, SRMs etc? That multitude of buttons, text field, check boxes, dropdownlists all precisely located on a screen? Good luck achieving that kind of complexity with just CSS. And these layouts migrate from desktop applications into web each day (keyword: software-as-a-service).

So choose what suits best your current need and don't trust those CSS lovers. Actually don't trust any fanatics at all.

User