div is arguably the most overused and misunderstood element in 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
divyou can do to any other tag
divis not special in that regard. You do not need to use a
divin order to access advanced CSS such as positioning.
divshould almost never contain a single element
Because anything you can do to a
divyou can do to any other element, wrapping a
divaround a single element is almost always redundant and unnecessary.
divis not a substitute for, or addition to, a block element
An unordered list, for example, already has a container element:
<ul>. Wrapping a
divis not necessary to add an extra border to an element
box-shadowto achieve the effect instead.
- Avoid setting
heighton div elements (in fact, avoid setting a
heighton all elements other than images).
Other than uses of
height: 100%, allow
divelements to find their own height, determined by their content.