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 div
s 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 div
s for that matter). And most importantly: they behave correctly in all browsers & versions!
So... why the obession with making div
s 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 table
s. I keep seeing div
s replacing all html
elements, like h1
..h6
, span
s, etc.
Why??
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With