简体   繁体   English

如何修改和设置简单形式的f.input标记

[英]How to modify and style a simple form f.input tag

I have a form in which I'm asking a user chose between a specific collection of options. 我有一个表单,我要求用户在特定的选项集合之间进行选择。 My form in my codebase looks like this: 我的代码库中的表单如下所示:

= f.label :recognition, "How did you hear about us?", required: false, class: "font required-field"

= f.input :recognition, input_html: { class: "recognitionStyling" }, collection: %w{article blog_post linkedin magazine_ad online_search referral twitter other}, required: false

Now sure this works, but I'm wanting to style this a little bit and having problems doing so. 现在确定这是有效的,但我想要这样做一点,并且有问题这样做。

What I have right now looks like this: 我现在拥有的是这样的:

在此输入图像描述

Yet what I am trying to get is something similar to this: 然而,我想要获得的是类似于此的东西:

在此输入图像描述

Is there a specific input that I would need to allow for this to happen? 是否有特定的输入需要允许这种情况发生? What I tried was to add a class on my input called recognitionStyling , which looks like the following, but I don't know if CSS is the way to make this modification. 我尝试的是在我的输入上添加一个名为recognitionStyling的类,它看起来如下,但我不知道CSS是否是进行此修改的方法。

.recognitionStyling{
  width: 100%;
}

You can consolidate the label into the input and add a placeholder within the input_html : 您可以将标签合并到输入中,并在input_html添加占位符:

= f.input :recognition, 
          input_html: { class: "recognitionStyling" }, 
          prompt: "-- SELECT ONE --", 
          collection: %w{article blog_post linkedin magazine_ad online_search referral twitter other}, 
          label: "How did you hear about us?", 
          required: true

You can download bootstrap for that. 你可以下载bootstrap。 Then you will have to add the .js and the .css to your assets. 然后,您必须将.js和.css添加到您的资产中。 For all files added, include them in the top part of your application.js or application.css file as showed here below (so without their extension). 对于添加的所有文件,将它们包含在application.js或application.css文件的顶部,如下所示(所以没有它们的扩展名)。

In assets/javascript/application.js : 在assets / javascript / application.js中:

//= require_bootstrap.min

In assets/stylesheets/application.css.scss 在assets / stylesheets / application.css.scss中

 *= require_bootstrap.min    

In the views/item/show.html.erb : 在views / item / show.html.erb中:

<div class="container">
<h2>Form control: select</h2>
<p>The form below contains two dropdown menus (select lists):</p>
<form role="form">
<div class="form-group">
  <label for="sel1">Select list (select one):</label>
  <%= f.select :recognition, input_html: { class: "form-control" }, collection: %w{article blog_post linkedin magazine_ad online_search referral twitter other}, required: false %>
</div>

check this link http://www.w3schools.com/bootstrap/bootstrap_forms_inputs.asp 点击此链接http://www.w3schools.com/bootstrap/bootstrap_forms_inputs.asp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM