You could use hook_menu_local_tasks_alter(). You can access all local tasks through the first parameter$data and you can add more class names to the option array localized_options of each tab.
function YOURMODULE_menu_local_tasks_alter(&$data, $router_item, $root_path){
if(isset($data['tabs'][0])){
$tabs = $data['tabs'][0];
$i = 1;
foreach($tabs['output'] as &$t){
if($i == 1) $class = 'first';
elseif($i = $tabs['count']) $class = 'last';
if(isset($t['#link']['localized_options']['attributes'])){
$attributes = $t['#link']['localized_options']['attributes'];
$attributes['class'][] = $class;
}else{
$attributes = array(
'attributes' => array(
'class' => array($class)
)
);
}
$t['#link']['localized_options'] = $attributes;
$i++;
}
$data['tabs'][0] = $tabs;
}
}
If you don't want to loop through all local tasks for performance sake, you can directly update$data['tabs'][0]['output'][0] and $data['tabs'][0]['output'][$data['tabs'][0]['count']-1]. But you should check if the indexes exist, otherwise you will get Warning: Undefined index...