Tutorial 2 - Floating an image and caption

Step 8 - Add a border to the image

To add a border to the image, you can use a Decendant Selector rule. The image and caption are inside the div so they are decendants of the div. This means you can target the image with a rule "div img". The problem with this rule is that it will target any image inside any div.

To be more specific, we can narrow down the selection by using "div.floatright img { border: 1px solid #ddd; }". This will target any image inside a div that is styled with a "floatright" class.

As the image has a border of 1px on either side, the width of the div should be changed from 100px to 102px (100px image, 1px left margin, 1px right margin = 102px).

Go to Step 9 →

Caption here

Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.

float: right;
width: 102px;
margin: 0 0 10px 10px;
background-color: #ddd;
padding: 10px;
border: 1px solid #666;

div.floatright img { border: 1px solid #000; }

<div class="floatright">
<img src="images/image.gif" alt="" width="100" height="100"><br>
Caption here
Lorem ipsum dolor sit amet, consectetuer...
Other Max Design articles and presentations
Associated with webstandardsgroup.org