By default, Drupal's core field.module with add 'odd' and 'even' classes to your field items, but it won't add 'first' and 'last' classes! This can quickly be remedied by overriding the core field.tpl.php file with your own custom one.
I'd recommend first copying /modules/field/theme/field.tpl.php into your site's theme folder. For me, the destination was
/sites/all/themes/grasmash/templates/field.tpl.php. Then clear your caches. This will force Drupal to check for new template files in your theme's directory, and select the new field.tpl.php as the prioritized template for generating fields.
Here's the business part of my customized field.tpl.php file:
<?php $max_delta = count($items) - 1; ?> <div class="<?php print $classes; ?> clearfix"<?php print $attributes; ?>> <?php if (!$label_hidden): ?> <div class="field-label"<?php print $title_attributes; ?>><?php print $label ?>: </div> <?php endif; ?> <div class="field-items"<?php print $content_attributes; ?>> <?php foreach ($items as $delta => $item): ?> <div class="field-item<?php print $delta % 2 ? ' odd' : ' even'; ?><?php print $delta == 0 ? ' first' : ''; ?><?php print $delta == $max_delta ? ' last' : ''; ?>"<?php print $item_attributes[$delta]; ?>><?php print render($item); ?></div> <?php endforeach; ?> </div> </div>
There are two important changes here:
<?php $max_delta = count($items) - 1; ?>counts the total number of field items in each field, allowing us to determine which field item should be given the 'last' class
<?php print $delta == 0 ? ' first' : ''; ?><?php print $delta == $max_delta ? ' last' : ''; ?>will print out our new sparkly classes.
You should note that this may add a small performance tax to your site by requiring PHP to count the $items array for every field, but I think that it is fairly negligible. Some people would prefer not to include this kind of logic in a template file at all. Let me know if you've got a better way!