
Originally Posted by
simmo
... I added #clear{overflow:...
That should have been .clear, not #clear. (dot) prefaces a class name, (hash) prefaces an fragment identification.
br class="clear" makes it reusable on the same page, if need be. br id="clear" makes it a single case in any one page. Class name is more appropriate in this case, imho.
Consider an outer container with content that floats around a positioned object, such as a photo surrounded by text on one side and below. If the text is sufficient to fill the container and force it to extend vertically below the bottom of the positioned object then there is no problem. The object fits nicely, and any border will wrap the whole works.
Here is a basic snippet to describe the above:
HTML Code:
<div>
<p>
<img width="125" height="200" alt="Picture of fixed height" />
this text would be plentiful enough to push the bottom of the container to greater
than 200 pixels in height, even when displayed on wide screen. No problem here.
If there is a border on this paragraph (or more likely the DIV) it will wrap around
nice and squarely.</p>
</div>
But let the text be sparse, say only a couple of lines, or so, and the problem will be very evident. The border will only wrap around the text, and not the whole section. The picture (and any border assigned to it) will extend below the border, and cause content below it to float as well. All very good if this was the design intention, but not very good if it was not. Worse yet, this problem is dealt with differently in the various browsers.
To cope with this issue, developers long ago devised what was commonly referred to as a 'clearing div' or clearing element of some sort. The BR class="clear' is one such element, with this distinct purpose in mind. It forces otherwise non-existent content to clear the positioned item in the float situation. This lets the border wrap the whole thing, even if it is mostly white space contained within.
HTML Code:
<div>
<p>
<img width="125" height="200" alt="Picture of fixed height" />
this text would be sparse, and not sufficient to float around the object.
</p>
<br class="clear />
</div>
The clearing element forces a full width element to take its place below the text and positioned object. Problem solved. Well, maybe.
Some further study on this issue, and the extra markup structure required to control it can be found all over the web. Position is everything, A List Apart, and others have covered it extensively. An alternative approach has been devised that uses less markup, generically known as 'clearfix.' Google it an d you will undoubtedly learn lots on this subject.