Based Layout vs Div

Possible Duplicate:
Why not use tables for layout in HTML?

I just want to know the difference between table-based layout and div-based layout. When should I use what and why?

Thanks in advance.


Very simply, table based layouts were the old way of organising the position of content and divs are the newer way. Think of them as being invisible rectangles (unless you choose to make them visible) that hold content and both have their pros and cons in how you are able to position them.

You can position divs into nearly every situation a table can be positioned into, whereas there's a lot of positioning you can do with divs that you can't do with tables. This is one reasons why using tables to layout your page is discouraged.

Tables haven't completely disappeared. They're still very good at (funnily enough) table-based display of information or statistics. Think excel-type layouts.


Tables should only ever be used for tabular data. It really is as simple as that.

As for why; a website layout isn't tabular data.

Also, a table will use more code in your page. For example; to create one 'box' you can either do this:

<table>
  <tr>
    <td>Box Content</td>
  </tr>
</table>

or this

<div>
  Box Content
</div>

With the div you can play with the absolute-position. So you can have thousand of div put wherever you want in your webpage. You can also put div above other div with z-index, which is more difficult with table.

The table looks less flexible, but give you a look more structured and also more compatible between browser.

My advice. Make your main structure with table and put inside it your div.

链接地址: http://www.djcxy.com/p/15486.html

上一篇: 使用表格或div

下一篇: 基于布局与Div