Chapter 10. Floating and Positioning
Sure, CSS makes content look good with font changes, backgrounds, and all the rest, but what about accomplishing basic layout tasks? Enter floating and positioning. These are the tools by which you can set up columnar layout, overlap one piece of layout with another, and generally accomplish everything that so many tables have been used for over the years.
The idea behind positioning is fairly simple. It allows you to define exactly where element boxes will appear relative to where they would ordinarily be—or relative to a parent element, another element, or even to the browser window itself. The power of this feature is both obvious and surprising. It shouldn’t shock you to learn that user agents support this element of CSS2 better than many others.
Floating, on the other hand, was first offered in CSS1, based on a capability that had been added by Netscape early in the Web’s life. Floating is not exactly positioning, but it certainly isn’t normal-flow layout either. We’ll see exactly what this means later in the chapter.
Floating
You are almost certainly acquainted
with the concept of floated elements. Ever since
Netscape 1, it has been possible to float images by declaring, for instance, <img src="b5.gif" align="right">
. This causes an
image to float to the right and allows other content (such as text) to “flow around” the
image. The name “floating,” in fact, comes from the document “Extensions to HTML 2.0,”
which stated:
The additions to ...
Get CSS: The Definitive Guide, 3rd Edition 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.