Take the 2-minute tour ×

so I am trying to indent the form given by this code.

<%= form_for([micropost, micropost.comments.build]) do |f| %>

    <div class="field">
      <p2>Who are you?</p2>
      <%= f.text_field :commenter %>
    <div class="field">
      <p2>What deal are you offering?</p2>
      <%= f.text_area :body %>
    <div class="actions">
      <%= f.submit "Submit"%>

Now my css file has this

/* forms */

input, textarea, select, .uneditable-input {
  border: 1px solid #bbb;
  width: 100%;
  padding: 10px;
  height: auto;
  margin-bottom: 15px;

and I could just add something like margin-left: 80px; but this would indent all of my input forms. How can I perhaps name this form differently so that I can talk to it with my css file? Or is there a better way?

share|improve this question
add comment

2 Answers

If you are using google chrome I would highly suggest using stylebot to test your css modifications in real time. SO helpful. https://chrome.google.com/webstore/detail/oiaejidbmkiecgbjeifoejpgmdaleoha

Also, what you need to do is add a unique id to the form or form element you wish to change.

For the whole form

<%= form_for([micropost, micropost.comments.build], :html => { :id => "blah_form" }) do |f| %>

For just one field

<%= f.text_area :body, :id => 'blah_field' %>

For further info on form_for:


share|improve this answer
ok well that doesnt give me an error, but it doesnt indent the form. I put in my css file. blah form {margin-left:80px;} should I be calling it differently? –  BigBoy1337 Jun 16 '12 at 4:47
well, in your css you need to put #blah_form input {margin-left:80px} –  Abram Jun 16 '12 at 4:49
add comment

Try this:

<%= form_for([micropost, micropost.comments.build], :html => {:id => "some_id" }) do |f| %>

This add an unique id to the form so you can indent it however you want in CSS and don't change others.

I mean, to only change it, you can define something for that id in you CSS.

share|improve this answer
hmm this gives me a syntax error. Any idea why? –  BigBoy1337 Jun 16 '12 at 4:45
Yes, because you need to put the :html symbol inside of the form_for(), as suggested in my answer –  Abram Jun 16 '12 at 4:48
sorry my bad, yes you have to put inside the form_for( ) –  qusr Jun 16 '12 at 5:07
You've got an extra ')' after build] –  Abram Jun 16 '12 at 5:09
add comment

Your Answer


