如何向 form_for 中的单个输入添加样式

问题描述 投票:0回答:2

我正在使用带有 HAML 的 Rails 框架,并且我有引导程序设置。我将如何单独格式化字段输入。我希望名称输入字段为屏幕左侧浮动的 60%,价格输入字段为屏幕左侧浮动的 25%。

我想我是在问如何将类添加到 form_for 中的单个输入中。 谢谢

= form_for @product,:url => products_path, :html => { :id => "fileupload", :multipart => true } do |f| 
  %p
    = f.label :name
    = f.text_field :name # i want to format this
  %p
    = f.label :price
    = f.text_field :price
ruby-on-rails ruby haml twitter-bootstrap-rails
2个回答
26
投票

您可以向任何表单助手添加一个类并使用 CSS 对其进行格式化:

= f.text_field :name, class: 'your_class' # i want to format this

当然你也可以直接设置样式选项,但建议将内容和样式分开。所以不要

= f.text_field :name, style: 'float: left; width: 60%; display: block' # i want to format this

0
投票
<%= f.password_field :password, class: "your style class", style: "display: block;" %>
© www.soinside.com 2019 - 2024. All rights reserved.