Paul
Paul

Reputation: 26690

Rails select tag - set specific option style

I want to select one of options in SELECT tag with special color.

How to do this following using Rails' f.select helper and options_for_select ?

<html>
<head>
  <style type="text/css">
    option.standard {background-color:#FFAAAA}
  </style>
</head>
<body>
  <select style="width:100px">
    <option selected="selected">1</option>
    <option>2</option>
    <option class="standard">3</option>
    <option>4</option>
    <option>5</option>
  </select>
</body>
</html>

Upvotes: 3

Views: 3193

Answers (1)

KARASZI Istv&#225;n
KARASZI Istv&#225;n

Reputation: 31477

As the documentation says for options_for_select, you can do it like this:

options_for_select([ 1, 2, [ 3, { :class => 'standard' }], 4, 5 ], [ 1 ])

Upvotes: 3

Related Questions