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
.
Here's HTML:
<div id="x01759"> <img id="xfloat947" 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>
Here's CSS:
#xfloat947 { float:left; margin:8px; } #x01759 { 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">
CSS, Layout
- CSS: Display Property
- Pure CSS Table
- CSS: 3-Column Side-Panel Layout
- CSS: Newspaper Text-Flow Over Multi-Column Layout
- CSS: Text Flow Around Image
- CSS: Hide Element (visibility)
CSS, Layers
- CSS: Position Property
- CSS: Fix Element to Window
- CSS: Position: Relative
- CSS: Absolute Position
- CSS: Text Over Image
- CSS: z-index