Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do most people want to avoid TABLEs in HTML and use DIVs for everything? [duplicate]

Tags:

html

css

This is something that makes me crazy every time I see it. Why is using div elements almost an obsession?

I understand why having mostly divs in the markup, each one with an id or (even better) a className can help develop a clean markup and keep control of visual changes.

But, for example, I keep seeing questions about how to make divs behave like a table, and even when they are told somethings will not be compatible with x or y browser version, they still want to do things like this:

<div style="display: table">
    <div style="display: table-row">
        <div style="display: table-cell">Content</div>
        <div style="display: table-cell">Content</div>
    </div>
    <div style="display: table-row">
        <div style="display: table-cell">Content</div>
        <div style="display: table-cell">Content</div>
    </div>
</div>

Why? ...really: Why??

Why is that better than using a table? Or, why is using tables something that abominable?

Tables are part of HTML elements. They exist for a reason and have a good purpose. They are not deprecated and they are not going to dissapear anytime soon (or sooner than divs for that matter). And most importantly: they behave correctly in all browsers & versions!

So... why the obession with making divs behave like tables? Why do so much people write HTML/CSS that way and then feel proud of something so dirty?

This is not exclusive to tables. I keep seeing divs replacing all html elements, like h1..h6, spans, etc.

Why??

like image 838
Francisco Zarabozo Avatar asked Oct 21 '22 11:10

Francisco Zarabozo


1 Answers

No, using divs that behave like table cells, just for the sake of avoiding table tags is not much better.

It is completely fine to use tables, where tables are appropriate. If you want to display tabular data, use tables. If you just use tables to layout your page in a grid-like environment, then no, don’t use tables.

The reason why people use divs with table behavior is usually because they don’t want to use tables, as they would have a semantical meaning, but they still want to stick to a tabular layout.

In the end, you should never use tables to layout pages though. Many good reasons are given here.

like image 57
poke Avatar answered Nov 15 '22 07:11

poke