Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why should I use display:table instead of table

Tags:

What's the benefits of structuring my site with divs and apply the display:table property ( display:tr, display:tr). Doesn't this mean that the divs will behave exactly like tr and td elements?

I know I probably shouldn’t use tables or table behavior for layout at all but I'm just curious if there's a difference and a benefit?

like image 877
picknick Avatar asked May 19 '10 16:05

picknick


People also ask

What is the purpose of display table?

Display tables can do the same thing. The goal is to elicit emotions in people so they want to stop and look at the merchandise. Less is more: When there are too many extraneous things on a table, everything seems to be in a jumble.

Why do professional designers no longer use tables for layout?

The World Wide Web Consortium (W3C®) discourages use of tables for layout because they are striving for a web in which content and structure are completely separate from presentation. This allows content to be rendered meaningfully across a wide variety of devices.

Why should we use div instead of table?

Using div is better than using table because of easy control of the in the design and it can be container for controls than table and the table is mainlt used to group data with simillar structure so it's design is for this task but div is considered as container mainly than table.


2 Answers

What's the benefits of structuring my site with divs and apply the display:table property ( display:tr, display:tr).

None whatsoever in my opinion, except that you take away compatibility with older browsers. The idea that using DIVs with display: table-* is somehow better than <table>s is idiotic IMO, and the result of totally misguided hysteria against table elements. (Not attacking you @Nimo, just criticizing some people who have taken the "tables are evil" meme too far.)

Tables are supposed to be used to represent tabular data, not to be misused for layouting.

There are, however, certain abilities that tables have that are still very hard to simulate using pure CSS. You either need massive hacks and sometimes even JavaScript based workarounds to make those things work.

You should design your layouts in a way that don't rely on those abilities.

In some rare cases, you do need them. But then, it doesn't matter whether you use a proper <table><tr> or a brain-dead <div style="display: table"><div style="display: table-row"> (which one is more semantic and better readable by the way?)

If you need display: table-* for your layout, you have one of those rare cases at hand, or you have painted yourself in a corner anyway. Either way, with a <table>, you at least get consistent browser support.

like image 107
Pekka Avatar answered Sep 24 '22 18:09

Pekka


The following explains why to use DIV over TABLE elements.

Pros of Table Element: Most designers use table for a consistent look. Tables are also easy to maintain. Another advantage of table is that it is compatible with the most browsers.

Cons of Table Element: All this comes with a cost: Too many nested tables increase page size and download time. More table elements push important content down so search spiders are less likely to add content to search engines.

Pros of DIV Element: div with CSS we can achieve the same table based page structure and reduce the number of elements on the page, which allows the page to load faster. It also makes page more compatible with search engine spiders.

Cons of DIV Element: The major drawback of this is not all CSS elements are not browser compatible. Because of this we have to write some custom CSS to resolve issues.

full article : http://www.codeproject.com/KB/HTML/DIVwebsite.aspx

display: table tells the element to display as a table. Nested elements should be displayed as table-row and table-cell, mimicking the good old TR's and TD's. There's also a display: table-column but it should show nothing at all, only serving for style information like a COL does. I'm not sure exactly how this works.

more about div display style : http://www.quirksmode.org/css/display.html

like image 43
Pranay Rana Avatar answered Sep 23 '22 18:09

Pranay Rana