Hi,
Is there is any way to specify the width and height of a form when using form_for
?
Thanks.
Hi,
Is there is any way to specify the width and height of a form when using form_for
?
Thanks.
The cleanest way is to set an ID or class for the form, and set the width and height for the form using CSS. In your view:
<% form_for ..., :html => { :class => "myform" } do |f| %>
...
<% end %>
Set the width and height of the form in public/stylesheets/application.css
:
form.myform {
width: 75%;
height: 500px;
/* Or fill in whatever width and height values you need */
}
Lastly, make sure that the application.css
stylesheet is included in your HTML layout. Your app/views/layouts/application.html.erb
should contain a line like this:
<%= stylesheet_link_tag "application" %>
A final note: Be careful about setting a specific height to your forms. If the form's content doesn't fit within the specified height, your form probably won't look as intended. You can prevent this by setting overflow: scroll
in your stylesheet right after the width and height declarations, but in most cases you're probably better off letting the form occupy the height it needs.