如何在form_for中为单个输入添加样式 [英] How to add styling to a single input in a form_for
本文介绍了如何在form_for中为单个输入添加样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在将Rails框架与HAML一起使用,并且具有引导程序设置.我将如何分别格式化字段输入.我希望名称的输入字段为屏幕的60%左浮动,而价格的输入字段为屏幕的25%右浮动.
I'm using the rails framework with HAML and I have bootstrap setup. How would I format the field inputs seperately. I want the input field for name to be 60% of the screen float left and the input for price to be 25% of the screen and float right.
我猜我在问如何在form_for中将类添加到单个输入中.谢谢
I guess i'm asking how do i add classes to single inputs in a form_for. Thanks
= 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
推荐答案
您可以将类添加到任何表单助手中,并使用CSS对其进行格式化:
you can add a class to any form helper and use CSS to format it:
= f.text_field :name, class: 'your_class' # i want to format this
当然,您也可以直接设置样式选项,但是建议将内容和样式分开.
of cause you can also set a style option directly, but it is recommended to separate content and styling. So don't
= f.text_field :name, style: 'float: left; width: 60%; display: block' # i want to format this
这篇关于如何在form_for中为单个输入添加样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文