demosthenes.info

I’m Dudley Storey, the author of Pro CSS3 Animation. This is my blog, where I talk about web design and development with , and . To receive more information, including news, updates, and tips, you should follow me on Twitter.

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.

You must be signed up in order to leave comments.

web developer guide

featured comment

by Aisling Brock in New Business Card Design

what i'm reading

A Feast for Crows: A Song of Ice and Fire: Book Four
A Feast for Crows: A Song of Ice and Fire: Book Four

what i'm watching

Prometheus: Collector's Edition (Bilingual) [Blu-ray 3D + Blu-ray + DVD + Digital Copy]
Prometheus: Collector's Edition (Bilingual) [Blu-ray 3D + Blu-ray + DVD + Digital Copy]

what i'm playing

Borderlands
Borderlands

what i'm hearing

Planets
Planets

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.