Is There a Disadvantage of Using 'Display:Table-Cell'On Divs

Is there a disadvantage of using `display:table-cell`on divs?

display: table-cell is perfectly fine to use, with just one downside..

It doesn't work in IE7 (or IE6, but who cares?): http://caniuse.com/#search=css-table

If you don't need to support IE7, then feel free to use it.

IE7 still has some usage, but you should check your Analytics, and then make a decision.


To answer your specific use case, you can do it without display: table-cell, provided that you don't need the height to adjust based on content:

http://jsfiddle.net/g6yB4/

<div class='clearfix'>
<div style='float:left; width:100px; background:red'>some content</div>
<div style='overflow:hidden; background:#ccc'>some more content</div>
</div>

(why overflow: hidden? With: http://jsfiddle.net/g6yB4/3/ vs without: http://jsfiddle.net/g6yB4/4/)

display:table versus using tables

If the information being displayed on the forum is tabular, then don't be afraid to use a table if it makes sense semantically.

For general page layout, personally I wouldn't use it. I'd stick to the typical block-level div layouts and floats. IE7 does not support display:table and there are other caveats, such as the fact that it will expand in width based on content. For the future, I look forward to when flexbox is fully supported.

I do occasionally use display:inline-block for centering dynamic list items and the like.

Actual table Vs. Div table

It is semantically incorrect to simulate data tables with divs and in general irrelevant to performance as rendering is instant. The bottle neck comes from JavaScript or extremely long pages with a lot of nested elements which usually in the old days is 100 nested tables for creating layouts.

Use tables for what they are meant to and div's for what they are meant to. The display table-row and cell properties are to utilize div layouts more then creating tables for data representations. Look at them as a layout columns and rows same as those you can find in a newspaper or a magazine.

Performance wise you have couple of more bytes with the div example, lol :)

Why should I use display:table instead of table

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.

Style div display table-row can be styled or not

Answer is yes to both of your questions, in fact there is lot more you can do with display:table using CSS styling

CSS has properties to make any element you wish behave as if it was a table element. You'll need to structure them essentially as you would a table, and it will be subject to the same source-order-dependency as a table, but you can do it. I'm not crapping on it either, it's genuinely useful sometimes. If that layout style solves a problem and has no negative order implications, use it.

Don't use inline styles, but just for understanding here's how that would go:

<section style="display: table;">
<header style="display: table-row;">
<div style="display: table-cell;"></div>
<div style="display: table-cell;"></div>
<div style="display: table-cell;"></div>
</header>
<div style="display: table-row;">
<div style="display: table-cell;"></div>
<div style="display: table-cell;"></div>
<div style="display: table-cell;"></div>
</div>
</section>

CSS

display: table                /* <table>     */
display: table-cell /* <td> */
display: table-row /* <tr> */
display: table-column /* <col> */
display: table-column-group /* <colgroup> */
display: table-footer-group /* <tfoot> */
display: table-header-group /* <thead> */

html table vs css display table

The display table let the element behave like a element without using a HTML table element, so probably you will have more flexibility on your development. So you will have the benefits of a table and the flexibility of development without table, becase tables are always difficult and and hard to work

css display:table vs html table , Which is more appropriate to use?

There's not a whole lot of advantages to using table markup for page layout other than for someone that doesn't want to learn proper HTML/CSS and/or is using some sort of WYSIWYG editor.

You definitely want to use tables for tabular data, however, as there are a lot of good accessibility reasons.

The advantages of CSS for page layout (over tables) is:

  • presentation is separated from content (which often means less HTML to deal with)
  • presentation is more flexible when updating
  • presentation is a lot easier to tailor to various devices/screens

The css display property of 'table' allows your your CSS to act more like a traditional table. This gives you the benefits of CSS, but lets you use your older table logic.

If you are well versed in CSS, about the only time you'd really want to leverage display: table is when you run into situations where you want to handle vertical centering of content...something that CSS in general seems to fail at. Do note that display: table, like a lot of CSS, does not work in older versions of IE.

Is a DIV inside a TD a bad idea?

Using a div instide a td is not worse than any other way of using tables for layout. (Some people never use tables for layout though, and I happen to be one of them.)

If you use a div in a td you will however get in a situation where it might be hard to predict how the elements will be sized. The default for a div is to determine its width from its parent, and the default for a table cell is to determine its size depending on the size of its content.

The rules for how a div should be sized is well defined in the standards, but the rules for how a td should be sized is not as well defined, so different browsers use slightly different algorithms.



Related Topics



Leave a reply



Submit