
Night shot of one of three recently dedicated light pavilions on Superior Avenue.
In the past I've discussed how the use of photos can enhance a Web site, but I've not discussed the code one uses to incorporate them. On campus, and elsewhere, Web designers use a variety of techniques to include their photos. Some will build complex tables to get their photos positioned just right while others will add something like hspace="5" vspace="5" align="right" into the img tag.
Neither of these is recommended by current standards (the latter is deprecated as of HTML 4.1 but is necessary in HTML e-mail) nor do these techniques give you the control you need. A better way to do this is with Cascading Style Sheets (CSS).
An easy way to include photos is to use the CSS property "float" to float the image to the right or left of the content that follows. One can float either the image itself or a container, such as a paragraph enclosing the image. I prefer to do the latter in case I wish to include a caption with the image.
One begins by opening the page's existing stylesheet and defining a new class to contain the image. On this blog I typically use a class I call "photoright." The code in the stylesheet looks something like:
.photoright {float: right; padding:2px 0px 8px 10px; margin: 0; font-size:90%; color: #7F8E29; font-style:italic; width: 200px;}

Close-up of different pavilion in daylight.
This picture uses a class without the
width defined. I can add line breaks
(with varying results) or let some of the comment
push past the edge. Note how this moves the photo in.
Once the class has been added to your stylesheet you can begin to incorporate it into your pages. As the image will float to the right of any content that follows, you will want to start a paragraph, using the new style, immediately before the accompanying text. For example, in this blog entry I've put this at the very beginning of my entry:
<p class="photoright200"><img alt="Blue Pavilion" src="http://blog.case.edu/webdev/2007/10/01/bluepavilion.jpg" width="200" height="300" /><br />Night shot of one of three recently dedicated light pavilions on Superior Avenue.</p>

Close-up of first pavilion, floated left.
In this example I've used a class that defines a width of 200 pixels, the same width as the photograph. Note that I've included a line break immediately before the caption. This ensures that the caption starts below the image. Without a break (or a space), some browsers might ignore the width and have the caption begin to the right of the image. The other two pictures are placed farther down in the copy, again preceding the adjacent text. (View source to see exact placement.) The middle image uses a different class that doesn't define the width. I've left some of the caption hanging out so you can see how that works.
I've included the classes .photoleft and .photoright in the Case template files. These are in the current, and some past, versions. If you are using an older version that doesn't include the classes, simply copy them from the appropriate color stylesheet. Not knowing what size photos one might wish to include, the templates do not include the width measurement, but you may add it in based on the sample above.
That is pretty much all there is to it. If you have any questions, comments or other ideas, please submit them in the comments below.
Comment by ob81 — October 2, 2007 @2:25 am
Comment by Auto Parts Car Parts — October 3, 2007 @1:42 am
Comment by dave — October 3, 2007 @1:59 pm
Comment by Heidi Cool — October 3, 2007 @6:46 pm
Comment by HDR — October 4, 2007 @11:05 pm
Comment by Mohamed — October 9, 2007 @2:14 pm
Comment by JamesCalvin — October 16, 2007 @11:40 pm
Comment by Internet Marketing Singapore — October 18, 2007 @1:35 pm
Comment by lime in the coconut — October 19, 2007 @9:10 am
Comment by gretchenaro — October 23, 2007 @9:01 am
Comment by Heidi Cool — October 23, 2007 @1:08 pm
Comment by Graiker aus München — October 28, 2007 @7:30 am
Comment by Travel, entertainment, dating and more — November 6, 2007 @2:54 am
Comment by Zaiah-Adu — November 21, 2007 @7:49 pm
Comment by car parts nanny — December 11, 2007 @8:20 pm
Comment by web info — December 20, 2007 @12:50 pm
Comment by Sam Wilkinson — January 3, 2008 @6:27 pm
Comment by David — January 4, 2008 @4:10 pm
Comment by Amie — January 9, 2008 @7:03 pm
Comment by Amie — January 9, 2008 @7:11 pm
Comment by Vincent @ Office Tips and Tricks — January 13, 2008 @9:17 am
Comment by Heidi Cool — January 15, 2008 @4:22 pm
Comment by Jonathan — January 17, 2008 @2:00 pm
Comment by Jonathan — January 17, 2008 @2:00 pm
Comment by Shawn Bishop — February 1, 2008 @2:42 pm
Comment by Web Consultant — June 20, 2008 @8:07 am