I would make the first and last divs different.
<div class="imglink_first"></div> <div class="imglink"></div> <div class="imglink"></div> <div class="imglink_last"></div>
Then your css can apply margin only to imglink .
Your full complement will be 696px - 4*160px = 696px - 640px = 56px . There are three fill areas, so each should be 56px/3 = 18.67px . Unfortunately, this is not an integer, so you need to round. 18px * 3 = 54px , leaving two extra pixels at the end of your div. In addition, you will need 18px/2 = 9px on the left and right side.
.imglink_first, .imglink, .imglink_last{ float: left; } .imglink{ margin: 0px 9px; }
Alternatively, you can use the CSS selector with :first-child and :last-child
<div class="image-row" style="width: 696px"> <div class="imglink"></div> <div class="imglink"></div> <div class="imglink"></div> <div class="imglink"></div> </div> .imglink{ float: left; margin: 0px 9px; } .image-row:first-child, .image-row:last-child{ margin: 0px; }
Although this is not supported in all browsers.
source share