Chapter 10. Floating and Positioning
For a very long time, floated elements were the basis of all our web
layout schemes. (This is largely because of the property clear, which
we’ll get to in a bit.) But floats were never meant for layout; their
use as a layout tool was a hack nearly as egregious as the use of tables
for layout. They were just what we had. Floats are quite interesting and useful in their own right, however. This is especially true given the recent addition of float shaping, which allows the
creation of nonrectangular shapes that content can flow past.
Floating
Ever since the early 1990s, it has been possible to float images
by declaring, for instance, <img src="b5.gif" alt="B4" 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, came
from the Netscape DevEdge page “Extensions to HTML 2.0,” which explained the then-new align attribute. Unlike HTML, CSS lets you float any element, from images to paragraphs to lists. This is accomplished using the property float.
For example, to float an image to the left, you could use this markup:
<imgsrc="b4.gif"style="float: left;"alt="b4">
As Figure 10-1 illustrates, the image “floats” to the left side of the browser window, and the text flows around ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access