Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DIV's vs. Tables or CSS vs. Being Stupid

Tags:

css

layout

I know that tables are for tabular data, but it's so tempting to use them for layout. I can handle DIV's to get a three column layout, but when you got 4 nested DIV's, it get tricky.

Is there a tutorial/reference out there to persuade me to use DIV's for layout?

I want to use DIV's, but I refuse to spend an hour to position my DIV/SPAN where I want it.

@GaryF: Blueprint CSS has to be the CSS's best kept secret.

Great tool - Blueprint Grid CSS Generator.

like image 628
roman m Avatar asked Sep 14 '08 10:09

roman m


People also ask

Which one is better table or div?

TABLEs are the correct technology for tabular data. DIVs are the correct technology for page layout and defining objects on the page (along with other block-level objects, i.e. heading, paragraphs, ul tags etc.).

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.

Why tables are not good in HTML?

HTML tables were originally intended to be used for presenting tabular data, not 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.

Should you still use HTML tables?

You should only use tables for tabular data, and tabular data generally looks like something you might display in a spreadsheet or possibly a database. However, HTML5 changed the rules and now tables for layout, while not recommended, are considered valid HTML.


2 Answers

There's the Yahoo Grid CSS which can do all sorts of things.

But remember: CSS IS NOT A RELIGION. If you save hours by using tables instead of css, do so.

One of the corner cases I could never make my mind up about is forms. I'd love to do it in css, but it's just so much more complicated than tables.

You could even argue that forms are tables, in that they have headers (labels) and data (input fields).

like image 123
Matthias Winkelmann Avatar answered Sep 30 '22 16:09

Matthias Winkelmann


In the UK and in US there is a legal requirement for favouring CSS layouts over Tables. Both Section 508 (US) and the Disability Discrimination Act (UK) cover accessibility standards for users with limited vision.

In the UK the legislation extends so far as to actually make it illegal to commercially produce a site that impedes the ability of a partially sighted user in the same way that it is now illegal to have a shop with a step to enter it and no way for a wheelchair user to get in - admittedly there have been no prosecutions over website accessibility yet. However I would always go with CSS as it means that your site design is so much easier to maintain in the longer term.

Investing time in learning CSS (I used W3C schools and .Net Magazine http://www.netmag.co.uk) will pay off.

like image 31
Mauro Avatar answered Sep 30 '22 14:09

Mauro