Align images using CSS

How to align images using valid XHTML/CSS?

the css part

.leftimg {
float: left;
}

.rightimg {
float: right;
}

the html part

<div class="leftimg">
<img src="someimage1.jpg" alt="alt_text_1" title="title_image_1" width="150" height="200" />
</div>

<div class="rightimg">
<img src="someimage2.jpg" alt="alt_text_2" title="title_image_2" width="150" height="200" />
</div>

How to center images using valid XHTML/CSS?

the css part

.centeredimage {
margin: 0 auto;
width: 500px;
text-align: center;
}

the html part

<div class="centeredimage">
<img src="someimage3.jpg" alt="alt_text_3" title="title_image_3"width="150" height="200" />
</div>

The image filename, alt text, title text, width, height could be changed according to your wish. The above code will validate as XHTML 1.0 strict.

HTML encoded using Centricle.com

Leave a Reply


Similar Entries

  • links for feb 12, 2006
  • ResizR - Resize images online
  • Free background images / patterns
  • Blogger launches free image hosting
  • View images without loading pages