div Play Dough
We don't want to add to page complexity by dumping a bunch of div
or other elements into the page design. At the same time, though, we don't want to shortchange ourselves by not trying out some new web design tricks just because they add more div
s to an existing stack of page elements.
Ten years ago, I wrote, "The div
element is the play dough of the Web." You can use it to group, contain, position, and frame. It has no semantics, so using it anywhere won't affect the meaning of the page. It has no accessibility constraints, so its use won't impact adversely on screen readers.
Figure 8-7. Using the background image column trick
The div
is not a replacement for other HTML elements. For instance, it's not a header element, and shouldn't be used in place of any of the hi–h6
header elements. It's also not a list item, and shouldn't be used in place of ul/li
or ol/li
. Nor is it a quote (blockquote), citation, address, abbreviation, and so on, to be used in place of these other, more meaningful page elements.
The div
is a way to define a section of the web page: nothing more, nothing less. However, for all the places where it shouldn't be used, it's the most important page element and, frankly, we'd still be back with layout-by-tables if it weren't for the div
element.
Aside from its layout capability, there are other uses for the div
element. Earlier in this book, I covered how ...
Get Painting the Web now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.