CSS: Text Flow Around Image
The float property can make text flow around an element
such as an image.
Text Flow Around Image Example
You can see the text flow around a image. This is done by making the image float with attribute float.
Code
<div id="zPQTS"> <img id="float-x3c4p" src="i/tile_B.png" alt="tile B" width="128" height="128" /> <div> The Time Traveller (for so it will be convenient to speak of him) was expounding a recondite matter to us… </div> </div>
#float-x3c4p { float: left; margin: 8px; } #zPQTS { max-width: 400px; }
The float can have a value of left or right.
When it's left, it aligns to the left.
When a element is floating, anything will go around it to avoid collision or overlap.
(except elements that have their own layer with position. 〔see CSS: Position Property〕)
Multiple consecutive HTML elements with float:left behave as sequence of inline-block elements such as
sequence of
HTML: Image Tag
, flowing from left to right.
Stop Flowing
If you have many floating elements, the position of the last item will be the position the next non-floating item begin. For example, you might have:
floatElement floatElement floatElement … <h2>…</h2>
The <h2> will be shown at the position right after the last flow, as if it is part of the flow.
If you don't want that, you need to stop the flow with clear:left in the element that comes after the float. Like this:
<h2 style="clear: both">A New Beginning</h2>
The clear can have values of left, right, both.
Usually, it is best to use this element to clear the floats:
<hr style="visibility: hidden; clear: both">