Lists vs. Divs

mrf's picture
public
mrf - Mon, 2008-03-31 13:37

So I took a look at the Drupal Markup Style Guidelines and one passage got me thinking.

If you're in doubt, put it in a div (and give it classes).

Don't leave content adrift on the page with no mark-up at all. Every chunk of html whether in a tpl file or a theme function should have a root DOM element. For module developers this is a div 95% of the time. In page.tpl.php it's the element. (or ?)

If we are truly looking to create semantic HTML throughout Drupal, many areas would be better served using a ul rather than divs wrapped within divs wrapped within divs. I first became introduced to how useful marking up lists of items as actual lists can be through Andy Clarke's Transcending CSS and have found it makes html much easier to comprehend when taken out of the context of its attached styles.

My question, is this really possible to include in Drupal? I already spit out most of my views as lists, this gets me one step closer, but what about including this into other areas of the markup that are also lists?

One problem I see is that the default styling for lists is almost completely unusable, so an approach like this would require a certain level of CSS knowledge to begin styling the lists in useful ways.

Any thoughts?


this is absolutely correct.

purrin's picture
purrin - Sun, 2008-04-13 22:57

this is absolutely correct. divs give no meaning at all by themselves, a little more with the proper use of meaningful ID's.. Andy's book does a beautiful job of illustrating how all the world can be marked up with different types of lists.. lists of lists.. and compound elements to add more clear meaning.

I think their idea of making a default 'when in doubt' sort of policy being a div is that for cms purposes it might be slightly more forgiving to use a block-level element.. since sidebars are all about weighting and stacking things up. That having been said, it's not really more complicated to do it the right way with lists. That is a frame of reference I would love to see the Drupal community take as a whole.


Yeah, I completely agree.

dixon_ - Mon, 2008-05-19 11:11

Yeah, I completely agree. Div's are really overused in Drupal core, where lists would be much more appropriate.

But as "mrf" mentioned above, we are facing a problem when using lists instead of divs. The default styling isn't what you want in most cases. But I think this is where the discussion of a "semantic base theme into core" comes in. It has been mentioned before. Think of a base theme that completely resets all default HTML styles (lists would then act more like a div with no padding, margin or list-style). This theme should then be really simple to extend through the theme layer in D6.

I haven't got much time this early spring, but I am in the process to make an proposal of a new "Markup Style Guideline". After that I will start submitting patches to get D7 core more semantic.