XML technologies / CSS / Advanced websites with CSS / Putting CSS in perspective / What is CSS actually for? / Images and CSS
(Excerpt from “CSS − Advanced websites with Cascading Stylesheets” by Rachel Andrew & Dan Shafer)
Images are inserted into HTML using the tag <img>. CSS offers limited control over an image’s appearance, but stylesheets still provide some interesting possibilities.
Like any other object on a web page, an image can be placed anywhere using the tag <div>. The tag <div> also lets you influence an image’s border and alignment, while a style rule can change the border’s appearance.
The following figure shows text flow beside an image without CSS. The image appears at the page’s left edge, aligned with the first text line’s baseline. Most of the paragraph appears below the image.
Figure: Image and adjacent text without CSS.
CSS is also particularly useful for wrapping text around images. The property float (described further in A simple CSS layout) lets you integrate an image neatly with its adjacent text. The following figure shows what happens when we position the image correctly using the property float. Text first flows around the image’s edge, then below it. This fits our design much better than the rendering in the preceding figure.
Figure: Image and adjacent text using float.
To let text wrap around every image on your page, add the following rule to your stylesheet:
img {
float: left;
}
Copyright © 2006 of the German translation, dpunkt.verlag GmbH
You may print the online version for your private use.
Otherwise, this chapter from “CSS − Anspruchsvolle Websites mit Cascading Stylesheets” is subject to the same conditions as the bound edition: the work, including all its parts, is protected by copyright. All rights reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
dpunkt.verlag GmbH, Ringstraße 19, 69115 Heidelberg
back to top