Html rails form_for 样式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1360346/
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
rails form_for styling
提问by Daniel
Is there a way to add styling to rails form_for and make it display inline?
有没有办法向 rails form_for 添加样式并使其显示内联?
回答by Andy Gaskell
There might be a cleaner way to do this, but it works. (I tried with another nested hash, no dice)
可能有一种更干净的方法来做到这一点,但它有效。(我尝试了另一个嵌套哈希,没有骰子)
<% form_for(@model, :html => { :style => 'background-color:red;' }) do |f| %>
回答by Christoph Schiessl
A even cleaner way would be to define the styling in an external stylesheet (like application.css
). form_for
creates a <form id="something"/>
tag with an id attribute. You can of course use this id in your stylesheet(s) to apply some specific styling to the form.
更简洁的方法是在外部样式表(如application.css
)中定义样式。form_for
创建一个<form id="something"/>
带有 id 属性的标签。你当然可以在你的样式表中使用这个 id 来对表单应用一些特定的样式。
回答by dalyons
Put it in a div of the appropriate class? Its a display thing, not a rails thing.
把它放在适当类的div中?它是一个显示的东西,而不是一个导轨的东西。
application.css:
应用程序.css:
.inline form { display: inline; }
form.html.erb
表单.html.erb
<div class="inline">
<%= form....
</div>