klondike-5-3226
klondike-5-3226

Reputation: 171

How can I change the length of a text_field in rails?

So I have this text field

<%= f.text_field :body, placeholder: "Make an offer ", :maxlength=>"254" %> 

right now it takes up 100% of the width of the box it is in. I want it to take up like 95%. So far I have tried (from other forum posts)

adding :columns => "50" this didn't affect it. I tried putting on an html tag , :html => { :id => "offer_form" } and then putting in my css file

#offer_form { width:50%;} 

this didn't work

any other suggestions?

edit:

I realized that in my css file I have under /forms/

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

}

and when i change the width here it works. but it affects all of the forms in the entire app (obviously)(ie they are all 98%). Is there a way that I can id just this field so that I can edit its width independently.

Upvotes: 13

Views: 29121

Answers (2)

alex
alex

Reputation: 3742

add :size=>"50" option to text_field

<%= f.text_field :body, :size=>"50", placeholder: "Make an offer ", :maxlength=>"254" %> 

Upvotes: 24

user229044
user229044

Reputation: 239301

Use CSS. The width of the field isn't related to its maximum characters.

input.body {
  width:95%;
}

Upvotes: 6

Related Questions