5

我正在使用Rail的'f_date_select'和Twitter Boostrap,结果如下所示。但是,我希望选择框很小(大小的一半)。f.date_select框的尺寸更小

我该怎么做?

<%= f.label :start_date, :class => "control-label"%> 
<%= f.date_select :start_date, :prompt => { :day => 'Select day', :month => 'Select month', :year => 'Select year' } %> 
<%= f.label :end_date, :class => "control-label"%> 
<%= f.date_select :end_date, :prompt => { :day => 'Select day', :month => 'Select month', :year => 'Select year' } %> 

回答

10

他们得到从选择元素的宽度引导:

select { 
    width: 220px; 
    border: 1px solid #cccccc; 
    background-color: #ffffff; 
} 

要修复,添加自己在覆盖底部文件:

select.date-select { 
    width:auto; 
    border: 1px solid #cccccc; 
    background-color: #ffffff; 
} 

下一个问题是应用该类到date_select元素。如果你只是在这里抛出:class =>“date-select”,Rails不会识别你正在尝试使用这两个选项和html_options。相反,你必须给每个经过的哈希:

<%= f.date_select :start_date, {:prompt => { :day => 'Select day', :month => 'Select month', :year => 'Select year' }}, {:class => 'date-select'} %> 

这将适用于你的类日期选到每个生成的三个选择对象。

1

从内存,样式选择框是一个恶梦,因为他们更像是浏览器组件(即,它们在不同的浏览器渲染风格的不同而不管)。

由于您使用Bootstrap,尽管您可以使用their jQuery dropdown component以及尽可能多的样式。

你必须调整你的Rails代码以适应。