Element-based selectors such as a
, img
or div
are mostly used for two purposes:
To clean up browser inconsistencies.
For example, h1 { font-size: 3em; }
will remove inconsistencies in default size between different browsers and versions of browsers.
To set the default behavior instead of a specific behavior.
For example, img { border: none; }
ensures that Internet Explorer will not display blue border around images when they are embedded in a link. If, on a page, there are a few images where I want to display a border and a few dozen of images where I don't, it's easier to img { border: none; }
, then to set a border on those images where I want a border.
In most websites, elements are positioned according to the browser defaults, and are float: left
only when needed. For those websites, div { float: left; }
wouldn't make sense: it doesn't remove any browser inconsistencies and it sets the specific behavior, rather than the default one.
On the other hand, some very specific websites may prefer float: left
to be the default. svidgen suggested fluid layouts. I think more about games. For example, I'm currently working on a game and nearly every element is position: absolute
, so #map div { position: absolute; }
makes sense.
To determine whether you should keep the div { float: left; }
, study:
How many div
s are actually float: left;
on the page,
How many are not,
Where float: left;
effect is cancelled, and how painful is that.
You may as well find that the effect is cancelled nearly in every class. I had that several times when maintaining legacy applications, encountering some weird styles such as div { font-size: 13px !important; }
.