This shows you the differences between two versions of the page.

Link to this comparison view

why_divs_are_better_than_tables [2020/06/01 22:53] (current)
Line 1: Line 1:
 +====== Why DIVs are Better than Tables ======
 +I struggle with the "DIV vs Table" argument myself. ​ Most web developers, with CSS experience, will agree that DIVs (or other styled elements) are better than tables for site layout, and I agree. ​ Where I generally struggle, however, is when it concerns tabular data.  I generally think tables are easier but in a recent project I found a darn good reason to use a DIV instead.
 +Think about this scenario. ​ You need to create a table for a list of products. ​ You are creating this for a site where you have a general idea of the width of columns to use, but you're not sure how many columns. ​ It could be 2, 3, or even 4.  Now, a list of products could certainly be considered tabular data.  Do you put the list in a table and write some programming to figure out where to break the table up, or do you use DIVs.  At first, I thought, lets use DIVs and float them left, then write some programming to throw in "​clear:​ left" as needed between rows.
 +What I realized, shortly, was that I didn't need "​clear:​ left" if I used DIVs.  If you wrap your DIVs in another container DIV, they will wrap automatically! ​ This is probably obvious to some, but for whatever reason I never considered it.
 +As a side note, my data is probably not really tabular in nature, since I was putting more than a single piece of text in each "​cell"​. ​ But, maybe I'll consider DIVs more frequently now.
comments powered by Disqus
why_divs_are_better_than_tables.txt · Last modified: 2020/06/01 22:53 (external edit)