When should I use tables, divs or uls?

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

When should I use <table> , <div> or <ul> ?

What are the main advantages and disadvantages of each one?


always try to use each tag according to its semantic character

  • <table> tables are for tabular data, not for layout alignment
  • <ul> is unordered list, it is nice to use <ul> tag for <a> links, because of no CSS fallback
  • <div> div has no semantic meaning, mostly used for alignment, however HTML5 comes with a lot of new tags as <header> , <footer> , <article> , <section> , <aside> which should be used insted of div tag

  • Semantically, you should use tables for tabular data, unordered lists for unordered lists, and divisions where there is no semantically-defined element available. However, there is room for interpretation. For example, some developers think of navigation menus as unordered lists, and thus use unordered list tags (probably heavily styled).

    Up to and including HTML4, there was a general lack of semantic elements, so developers felt the need to fall back to using divisions very often. However, HTML5 introduces a range of block-level, semantic elements that define document structure and have more meaning than divisions, though they should behave the same. These new tags include article, section, footer, nav, aside and header.


    this is a matter of some debate, and I present only my personal view here:
    I think you should use tables only when you have to display tabular data.
    do NOT use tables for positioning / layout purposes; use divs and css for that.
    see this question for more details.

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

    上一篇: 表格与CSS的定位和设计

    下一篇: 我应该何时使用表格,div或uls?