demosthenes.info

A blog by Dudley Storey on , , , , , , and anything else that strikes his fancy.

featured articles

popular favourites

Introduction to divs

There are several HTML elements that I have not introduced to this point because without CSS they have little point, and almost no meaning. These elements include span and div.

div is arguably the most overused and misunderstood element of the HTML specification, so let’s try to kill a few common mistakes right off the bat:

In CSS, anything you can do to a div you can do to any other tag.

div is not special in that regard. You do not need to use a div in order to access advanced CSS such as .

A div should almost never contain a single element.

Because anything you can do to a div you can do to any other element, wrapping a div around a single element is almost always redundant and unnecessary.

A div is not a substitute for, or addition to, a block element.

An unordered list, for example, already has a container element: <ul>. Wrapping a <div> around the <ul> is redundant.

A div is not necessary to add an extra border to an element.

Use the outline property or a CSS3 trick with box-shadow to achieve the effect instead.

Avoid setting height on divs (in fact, avoid setting a height on all elements other than images).

Other than uses of height: 100%, allow divs to find their own height, judged by their content.

web developer guide

featured comment

by JoelB in Goodbye, JQuery Validation: HTML5 Form Errors With CSS3

what i'm reading

A Storm of Swords: A Song of Ice and Fire: Book Three
A Storm of Swords: A Song of Ice and Fire: Book Three

what i'm watching

Californication: The Third Season
Californication: The Third Season

what i'm playing

Mass Effect 3 Collector's Edition
Mass Effect 3 Collector's Edition

what i'm hearing

Dub FX
Dub FX

blogs

podcasts

no ads ever

This blog is free of advertising, and always will be.

creative commons licensed

The content of this blog is free to use in whatever way you wish under the Creative Commons license.