Tutorial 3 - Floating a series of "clear: right" images

Step 5 - Remove margin-top on the paragraph

You may have noticed that the top of the paragraph of text and the "float: right" image did not line up. This was due to a margin on top of the paragraph.

Non-styled paragraphs generally have 1em margin on top and bottom - the equivalent of one line of text. If you want to remove this margin, use "p { margin-top: 0; }". When applied, the paragraph and div will be vertically aligned (see below).

Will this affect paragraphs on the page making them run directly under one another? The answer is no. As mentioned above, paragraphs have 1em margin on top and bottom. If top margins are removed, it will only affect the first paragraph inside a container. All other paragraphs will still be separated to a height of 1em via the bottom margin.

Go to all steps combined →

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.

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.



CSS CODE
.floatright
{
float: right;
margin: 0 0 10px 10px;
clear: right;
}

p { margin-top: 0; }

HTML CODE
<img class="floatright" src="images/image.gif" alt="" width="60" height="60">
<img class="floatright" src="images/image.gif" alt="" width="60" height="60">
<img class="floatright" src="images/image.gif" alt="" width="60" height="60">
<p>
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.
</p>
<p>
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.
</p>
<p>
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.
</p>
Other Max Design articles and presentations
Associated with webstandardsgroup.org