bootstrap类不能与select一起使用

时间:2014-04-21 12:44:41

标签: css ruby-on-rails ruby twitter-bootstrap

我正在研究rails应用程序上的ruby并尝试减少select的大小。我有' bootstrap gem'为我的应用程序安装。 这是代码

 <%= f.select :fromyear, (1995..Time.now.year).to_a.reverse, 
     :include_blank => {:year => "Select year"}, :class=>"input-small" %>

因为我注意到了这个问题Change width of select tag in Twitter Bootstrap中的类值。但似乎它不适合这个选择。我试过了

<%= f.select :fromyear, (1995..Time.now.year).to_a.reverse, 
    :include_blank => {:year => "Select year"}, :style=>"100px" %>

但没有发生任何事。 Plz让我知道我错过了什么。感谢

4 个答案:

答案 0 :(得分:2)

根据f.selectform_for)的语法:

f.select(method, choices = nil, options = {}, html_options = {}, &block)

现在您将include_blankclass作为options参数传递,这就是class未应用的原因。 class必须进入html_options

您需要做的只是分开 optionshtml_options。:

 <%= f.select :fromyear, (1995..Time.now.year).to_a.reverse, 
     {:include_blank => {:year => "Select year"}}, :class=>"input-small" %>
     ^                                          ^ 
   ## Added a curly bracket to separate out `include_blank` option and `class` option.

答案 1 :(得分:1)

也许你忘记输入宽度&#39;在选项中:样式?

:style=>"width:100px"

答案 2 :(得分:1)

你尝试过这种方式吗?

= a.input :country, :as => :select, :collection => country_code_localized_map, :include_blank => false, :input_html=>{:class => "reg-input"}

或者你可以在select标签上方添加另一个%DIV.select_above_class并通过上面的类应用样式来选择标签

.select_above_class select{
   // your css styles
}

答案 3 :(得分:0)

试试这个

<%= f.select(:fromyear, options_for_select((1995..Time.now.year).to_a.reverse), {:include_blank => 'Select year'}, { :class => 'input-small' }) %>

或者您甚至可以在

选择标记内包含内联样式
<%= f.select(:fromyear, options_for_select((1995..Time.now.year).to_a.reverse), {:include_blank => 'Select year'}, { :class => 'input-small', :style => 'width:200px;', required: true }) %>