views:

245

answers:

3

I'm totally confused on this matter, some say use tables and others say it's a bad practice to make use of tables and div tags should rather be used. What is the correct way when developing sites for mobile devices .mobi

+3  A: 

You should use tables for presenting tabular data, not for layout. Most modern Web browsers on mobile phones (e.g. Mobile Safari on the iPhone) are quite capable of properly rendering websites that use CSS and semantic markup appropriately.

John Topley
One caveat I would add to this answer is that you need to make sure you understand your target audience. If its smartphone users in US or Europe, then yes, divs are the way to go. If your target audience is feature phone users then the browsers will be less sophisticated and you'll need to rely on tables for layout. If it's both then you should look into differentiating based on the mobile device/browser. For this look into frameworks such as WURFL or DeviceAtlas.
Kevin
@Kevin That's a good point.
John Topley
+1  A: 

The important aspect to consider is the difference between data & its actual layout on the screen.

Typically, tabular data should be presented using tables. For example, consider a company balance sheet as an example of tabular data which can be shown using HTML tables.

But, if you need to show normal content (which is not tabular in nature) in rows & columns, there are other alternatives like using DIV & SPAN tags and a bit of CSS to position & style the content to make it look like a tabular layout. A typical example of such a layout could be a news article shown on a newspaper. While the layout is in rows & columns, the news content itself is non-tabular.

There are tons of articles out there which debate why this is a good practice.

Given your case, I would recommend stick to normal DIV-based structure with CSS-based styling to give the desired effect & use TABLEs for tabular data.

HTH.

Sunny
+2  A: 

Yes, theory says that you should use tables for presenting tabular data, not for layout. But most of web browsers in the market do not properly render complex layouts with floating divs, advanced CSS, etc.

Things are changing quickly, and as other people have already said, most modern Web browsers on mobile (smart)phones (iPhone, Android...) come with a great HTML/CSS/Javascript support.
If you only have these devices in mind, you can go with DIV/CSS layouts, as it is the right choice from a semantic point of view. But if you want to cover a wide range of devices, use tables as you'll guarantee your pages are going to render properly in more devices.

Mobile market is so fragmented that sometimes using platforms such as MyMobileWeb, that automatically adapt contents for the user device, is a good idea.

Guido