Can’t Align Images in Wordpress? Fix it

Wordpress 2.5+ introduced a new image gallery system and correspondingly a new way to align images which was relatively intricate compared to the old one.

The main problem I faced using the new system until now was that I couldn't make Wordpress align the images properly for me. I thought I was the only one facing this problem but a helpful post by Daniel made it clear that there are perhaps more users facing the same problem.

I am sharing the fix just in case someone comes searching through to find a fix for this problem. All you need to do is add the following piece of CSS code to your theme stylesheet and you are good to go.

img.centered {
 display: block;
 margin-left: auto;
 margin-right: auto; 
}  img.alignright { 
padding: 4px; 
margin: 0 0 2px 7px;
 display: inline; }
  img.alignleft { 
padding: 4px;
 margin: 0 7px 2px 0; d
isplay: inline; } 
 .alignright { float: right; }
  .alignleft { float: left; }

This will make Wordpress aware of all alignments.