开发者

Using table or div [duplicate]

This question already has answers here: Why not use tables for layout in HTML? [closed] (66 answers) Closed 5 years ago.开发者_如何学编程

What is the best practice when building our web page div or table?

Someone says the div is recommended, but I found it is not easy to control the size and alignment with div.

What is your opinion?


It depends entirely on what you're wanting to display:

  • <DIV> and <SPAN> is for page layout
  • <Table> is for displaying tabular data (such as data points etc)

The days of using <table> for whole page layouts is gone - and you should be discouraged for using them for this reason.

HTML tags are meant to be semantic. This means describing the data it contains - not how to display it (this is for stylesheets to handle)


There's nothing fundamentally wrong with TABLE - it's just that it was historically overused for the wrong thing. In general, try to use TABLE for true tables of data, use DIV and SPAN for logical block or inline containers of content.


Tables should only be used to display data in a tabular way. For layout and design it is best practise to use divs and stylesheets.

Controlling the divs using stylesheets can take a while if you're not used to it, but it's quite easy to pick up.

You'll be thankful you did it later when the client wants the whole site redesigned and it means you don't have to undo the entire page in order to make the required changes.


First read this: http://www.smashingmagazine.com/2009/04/08/from-table-hell-to-div-hell/

In my opinion (which I'm sure some people will groan about subjective questions being asked on Stack Overflow), but I prefer using div's. A div tag is one tag, a table takes many tags to create a correctly marked-up table element.

A lot of websites in the 1990s were built with tables, but the thinking nowadays in to use divs.


I would say that div is definitely the industry standard for website layouts. They can be quite cumbersome to work with at first but once you get your head around how they are positioned then you will never look at tables again.

Try this tutorial for moving from tables to divs. http://www.devarticles.com/c/a/Web-Style-Sheets/DIV-Based-Layout-with-CSS/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜