Yii: How to add CSS class to a dropdown list

php, yii

Solution

You can use `htmlOptions` argument of `CActiveFrom::dropDownList()` to specify `class`,`style` or any other HTML attributes.

<?php echo $form->labelEx($model,'chassis'); ?>
<?php echo $form->dropDownList($model, 'chassis',
      array('saloon' => 'saloon', 'station wagon' => 'station wagon', ),
      array('class'=>'your_class_name'),
   ); 
?>

Problem

I am using Yii 1.1.10. I would like to know how to add a CSS class to a dropdown list. I am using a CActiveForm for example, how would i add a CSS class to this dropdown list? ``` <?php echo $form->labelEx($model,'chassis'); ?> <?php echo $form->dropDownList($model, 'chassis', array('saloon' => 'saloon', 'station wagon' => 'station wagon', ), ); ?> ``` EDIT: I had this in my code ``` array('empty' => 'Select one of the following...') ``` i had it there to make it the default message. but somehow it interfered with using ``` 'htmlOptions'=>array('class'=>'yourCssClass') ``` OR ``` array('class'=>'your_class_name') ``` so as long as i remove it, both suggestions work!Thank guys

Original source