You may write the code for displaying some rows of images with the margin you want, then at the image you don't want margins applied to, you link a class and provide a different style. You can also use the :not pseudoelement.
HTML
<div class="image-margin"> <img src="whatyouwant"> <img src="whatyouwant"> <img src="whatyouwant"> <img src="whatyouwant" class="image-no-margin"> </div>
CSS
.image-no-margin { margin:0px } .image-margin img:not(.image-no-margin) { 0px 5px 5px 0px; //5px top and 5px left }
This code means that you apply margin 0px to the images with class image-no-margin and the other style you defined (with 5px margin bottom and right) to all the other images (not image-no-margin).
The pseudoelement :not is supported only by Internet Explorer 9+ , latests versions of Firefox, Chrome, Safari and Opera. You can add support for Internet Explorer 6+ by using a javascript library called selectivizer.
You just need to download the library and include it in the head of your webpage:
<script type="text/javascript" src="[JS library]"></script> <!--[if (gte IE 6)&(lte IE 8)]> <script type="text/javascript" src="selectivizr.js"></script> <noscript><link rel="stylesheet" href="[fallback css]" /></noscript> <![endif]-->