Html 如何更改 rails 中 text_field 的长度?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13078098/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 03:35:24  来源:igfitidea点击:

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

htmlcssruby-on-rails-3textfield

提问by klondike-5-3226

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)

现在它占据了它所在盒子宽度的 100%。我希望它占据 95%。到目前为止我已经尝试过(来自其他论坛帖子)

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

添加:columns => "50"这并没有影响它。我尝试放置一个 html 标签,:html => { :id => "offer_form" }然后放入我的 css 文件

#offer_form { width:50%;} 

this didn't work

这没有用

any other suggestions?

还有其他建议吗?

edit:

编辑:

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

我意识到在我的 css 文件中我有 / 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.

当我在这里更改宽度时,它会起作用。但它会影响整个应用程序中的所有表单(显然)(即它们都是 98%)。有没有办法可以只识别这个字段,以便我可以独立编辑它的宽度。

采纳答案by meagar

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

使用 CSS。字段的宽度与其最大字符数无关。

input.body {
  width:95%;
}

回答by alex

add :size=>"50"option to text_field

:size=>"50"向 text_field添加选项

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