How can I add a CSS class to a View Field programmatically? Using template_preprocess_field doesn't work, I assume, because this is a field from a View, not a node. 

I've looked at this answer however that only seems to apply to the field value not the markup and styles surrounding it.

For example: The output of the field in markup is currently:

&lt;div class="views-field views-field-field-status"&gt;
    &lt;div class="field-content"&gt;
        Active
    &lt;/div&gt;
&lt;/div&gt;


I'd like to conditionally add classes:

&lt;div class="views-field views-field-field-status"&gt;
    &lt;div class="field-content my-conditionally-added-class"&gt;
        Active
    &lt;/div&gt;
&lt;/div&gt;
You can add any css class, HTML tag to any field through views admin UI, why don't you add the class from there?



UPDATE

Because you need add the css class based on some condition, you have to use the following preprocess function. your code is going to be some thing like this (maybe a few modification will be needed )

function mytheme_preprocess_views_view_field(&amp;$vars){
     $view = $vars['view'];
    if($YOUR_CUSTOM_CONDITION == TRUE &amp;&amp; $view-&gt;name == VIEW_NAME)
           $vars['classes_array'] = 'my-conditionally-added-class';
}


because you output the content on views you have to use mytheme_preprocess_views_view_field function.

For more information visit Themeing Views field output with Preprocess function.